Function to copy a file from a source path to a destination path.
(src, dst string)
| 532 | |
| 533 | // Function to copy a file from a source path to a destination path. |
| 534 | func copyFile(src, dst string) error { |
| 535 | in, err := os.Open(src) |
| 536 | if err != nil { |
| 537 | return fmt.Errorf("failed to open source file: %w", err) |
| 538 | } |
| 539 | defer in.Close() |
| 540 | |
| 541 | out, err := os.Create(dst) |
| 542 | if err != nil { |
| 543 | return fmt.Errorf("failed to create destination file: %w", err) |
| 544 | } |
| 545 | defer out.Close() |
| 546 | |
| 547 | if _, err = io.Copy(out, in); err != nil { |
| 548 | return fmt.Errorf("failed to copy file contents: %w", err) |
| 549 | } |
| 550 | return out.Close() |
| 551 | } |
| 552 | |
| 553 | // Function to recursively copy a directory. |
| 554 | func copyDir(src, dst string) error { |
no test coverage detected