|
1 | 1 | package builder |
2 | 2 |
|
3 | | -// Copy "recursivelies copy a file object from source to dest while perserving |
| 3 | +// Copy a file object from source to dest while preserving the file mode. |
| 4 | +// If the source is a directory, it will recursively copy all files and directories. |
4 | 5 | import ( |
5 | 6 | "fmt" |
6 | 7 | "io" |
@@ -57,33 +58,33 @@ func copyDir(src, dest string) error { |
57 | 58 | func copyFile(src, dest string) error { |
58 | 59 | info, err := os.Stat(src) |
59 | 60 | if err != nil { |
60 | | - return fmt.Errorf("error reading src file stats: %s", err.Error()) |
| 61 | + return fmt.Errorf("error reading src file stats: %w", err) |
61 | 62 | } |
62 | 63 |
|
63 | 64 | err = ensureBaseDir(dest) |
64 | 65 | if err != nil { |
65 | | - return fmt.Errorf("error creating dest base directory: %s", err.Error()) |
| 66 | + return fmt.Errorf("error creating dest base directory: %w", err) |
66 | 67 | } |
67 | 68 |
|
68 | 69 | f, err := os.Create(dest) |
69 | 70 | if err != nil { |
70 | | - return fmt.Errorf("error creating dest file: %s", err.Error()) |
| 71 | + return fmt.Errorf("error creating dest file: %w", err) |
71 | 72 | } |
72 | 73 | defer f.Close() |
73 | 74 |
|
74 | 75 | if err = os.Chmod(f.Name(), info.Mode()); err != nil { |
75 | | - return fmt.Errorf("error setting dest file mode: %s", err.Error()) |
| 76 | + return fmt.Errorf("error setting dest file mode: %w", err) |
76 | 77 | } |
77 | 78 |
|
78 | 79 | s, err := os.Open(src) |
79 | 80 | if err != nil { |
80 | | - return fmt.Errorf("error opening src file: %s", err.Error()) |
| 81 | + return fmt.Errorf("error opening src file: %w", err) |
81 | 82 | } |
82 | 83 | defer s.Close() |
83 | 84 |
|
84 | 85 | _, err = io.Copy(f, s) |
85 | 86 | if err != nil { |
86 | | - return fmt.Errorf("Error copying dest file: %s\n" + err.Error()) |
| 87 | + return fmt.Errorf("error copying dest file: %w", err) |
87 | 88 | } |
88 | 89 |
|
89 | 90 | return nil |
|
0 commit comments