Skip to content

Commit

Permalink
Update copyfiles.go
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkfella authored Jan 28, 2025
1 parent bd6f3b6 commit 12c54aa
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions copyfiles.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
// copyfiles.go
package main

import (
"fmt" // Import fmt to use for printing messages
"fmt"
"io"
"os"
"log"
"path/filepath"
)

func copyFile(srcPath, dstPath string) error {
// Open the source file
srcFile, err := os.Open(srcPath)
if err != nil {
return err
}
defer srcFile.Close()

// Check if the destination file already exists
if _, err := os.Stat(dstPath); err == nil {
// If the file exists, overwrite it
fmt.Printf("Overwriting file: %s\n", dstPath) // Use fmt to print message
fmt.Printf("Overwriting file: %s\n", dstPath)
} else {
// If the file doesn't exist, create it
fmt.Printf("Creating new file: %s\n", dstPath) // Use fmt to print message
fmt.Printf("Creating new file: %s\n", dstPath)
}

// Create or overwrite the destination file
dstFile, err := os.Create(dstPath)
if err != nil {
return err
}
defer dstFile.Close()

// Copy the contents of the source file to the destination file
_, err = io.Copy(dstFile, srcFile)
return err
}
Expand All @@ -42,12 +35,10 @@ func main() {
srcDir := "/opt/cni/bin/"
dstDir := "/host/opt/cni/bin/"

// Read the source directory and copy each file
err := filepath.Walk(srcDir, func(srcPath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Skip directories
if info.IsDir() {
return nil
}
Expand Down

0 comments on commit 12c54aa

Please sign in to comment.