diff --git a/copyfiles.go b/copyfiles.go index c82308e..3e3405b 100644 --- a/copyfiles.go +++ b/copyfiles.go @@ -1,8 +1,7 @@ -// copyfiles.go package main import ( - "fmt" // Import fmt to use for printing messages + "fmt" "io" "os" "log" @@ -10,30 +9,24 @@ import ( ) 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 } @@ -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 }