MCPcopy
hub / github.com/ChineseSubFinder/ChineseSubFinder / CopyFile

Function CopyFile

pkg/util.go:272–299  ·  view source on GitHub ↗

CopyFile copies a single file from src to dst

(src, dst string)

Source from the content-addressed store, hash-verified

270
271// CopyFile copies a single file from src to dst
272func CopyFile(src, dst string) error {
273 var err error
274 var srcFd *os.File
275 var dstFd *os.File
276 var srcInfo os.FileInfo
277
278 if srcFd, err = os.Open(src); err != nil {
279 return err
280 }
281 defer func() {
282 _ = srcFd.Close()
283 }()
284
285 if dstFd, err = os.Create(dst); err != nil {
286 return err
287 }
288 defer func() {
289 _ = dstFd.Close()
290 }()
291
292 if _, err = io.Copy(dstFd, srcFd); err != nil {
293 return err
294 }
295 if srcInfo, err = os.Stat(src); err != nil {
296 return err
297 }
298 return os.Chmod(dst, srcInfo.Mode())
299}
300
301// CopyDir copies a whole directory recursively
302func CopyDir(src string, dst string) error {

Callers 4

saveFullSeasonSubMethod · 0.92
CopySub2CacheFunction · 0.92
CopyFiles2DebugFolderFunction · 0.70
CopyDirFunction · 0.70

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected