Skip to content

Commit

Permalink
fix: copy file
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jul 21, 2023
1 parent 839f323 commit c63170a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func Run(configFilename, lockFile, version string, noConfigure, dryRun, withdraw
}

// Copying manual configs
if err := util.CopyFileGlob(path.Join(c.BIRDDirectory, "manual*.conf"), c.CacheDirectory); err != nil {
if err := util.CopyFileToGlob(path.Join(c.BIRDDirectory, "manual*.conf"), c.CacheDirectory); err != nil {
log.Fatalf("Copying manual config files: %v", err)
}

Expand Down Expand Up @@ -825,7 +825,7 @@ func Run(configFilename, lockFile, version string, noConfigure, dryRun, withdraw
// Copy config file
log.Debug("Copying Pathvector config file to cache directory")
if err := util.CopyFile(configFilename, path.Join(c.CacheDirectory, "pathvector.yml")); err != nil {
log.Fatalf("Copying pathvector config file to cache directory: %v", err)
log.Fatalf("Copying Pathvector config file to cache directory: %v", err)
}

if !dryRun {
Expand Down
26 changes: 21 additions & 5 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,25 @@ func Ptr[T any](a T) *T {
}

// CopyFile copies a file from a source to destination
func CopyFile(source, destination_dir string) (err error) {
func CopyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
_, err = io.Copy(out, in)
defer out.Close()
return err
}

// CopyFileTo copies a file from a source to destination directory
func CopyFileTo(source, destinationDir string) (err error) {
_, destination := filepath.Split(source)
destination = filepath.Join(destination_dir, destination)
destination = filepath.Join(destinationDir, destination)
src, err := os.Open(source)
if err != nil {
return err
Expand Down Expand Up @@ -189,14 +205,14 @@ func CopyFile(source, destination_dir string) (err error) {
return nil
}

// CopyFileGlob copies files by glob to a destination
func CopyFileGlob(glob, dest string) error {
// CopyFileToGlob copies files by glob to a destination
func CopyFileToGlob(glob, dest string) error {
files, err := filepath.Glob(glob)
if err != nil {
log.Fatal(err)
}
for _, f := range files {
if err := CopyFile(f, dest); err != nil {
if err := CopyFileTo(f, dest); err != nil {
return err
}
}
Expand Down

0 comments on commit c63170a

Please sign in to comment.