MCPcopy Index your code
hub / github.com/dnote/dnote / CopyFile

Function CopyFile

pkg/cli/utils/files.go:121–156  ·  view source on GitHub ↗

CopyFile copies a file from the src to dest

(src, dest string)

Source from the content-addressed store, hash-verified

119
120// CopyFile copies a file from the src to dest
121func CopyFile(src, dest string) error {
122 in, err := os.Open(src)
123 if err != nil {
124 return errors.Wrap(err, "opening the input file")
125 }
126 defer in.Close()
127
128 out, err := os.Create(dest)
129 if err != nil {
130 return errors.Wrap(err, "creating the output file")
131 }
132
133 if _, err = io.Copy(out, in); err != nil {
134 return errors.Wrap(err, "copying the file content")
135 }
136
137 if err = out.Sync(); err != nil {
138 return errors.Wrap(err, "flushing the output file to disk")
139 }
140
141 fi, err := os.Stat(src)
142 if err != nil {
143 return errors.Wrap(err, "getting the file info for the input file")
144 }
145
146 if err = os.Chmod(dest, fi.Mode()); err != nil {
147 return errors.Wrap(err, "copying permission to the output file")
148 }
149
150 // Close the output file
151 if err = out.Close(); err != nil {
152 return errors.Wrap(err, "closing the output file")
153 }
154
155 return nil
156}

Callers 2

CopyFixtureFunction · 0.92
CopyDirFunction · 0.85

Calls 3

OpenMethod · 0.80
CreateMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected