MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / CopyFile

Function CopyFile

pkg/utils/file.go:19–42  ·  view source on GitHub ↗

CopyFile File copies a single file from src to dst

(src, dst string)

Source from the content-addressed store, hash-verified

17
18// CopyFile File copies a single file from src to dst
19func CopyFile(src, dst string) error {
20 var err error
21 var srcfd *os.File
22 var dstfd *os.File
23 var srcinfo os.FileInfo
24
25 if srcfd, err = os.Open(src); err != nil {
26 return err
27 }
28 defer srcfd.Close()
29
30 if dstfd, err = CreateNestedFile(dst); err != nil {
31 return err
32 }
33 defer dstfd.Close()
34
35 if _, err = CopyWithBuffer(dstfd, srcfd); err != nil {
36 return err
37 }
38 if srcinfo, err = os.Stat(src); err != nil {
39 return err
40 }
41 return os.Chmod(dst, srcinfo.Mode())
42}
43
44// CopyDir Dir copies a whole directory recursively
45func CopyDir(src, dst string) error {

Callers 2

CopyDirFunction · 0.70
SymlinkOrCopyFileFunction · 0.70

Calls 7

CreateNestedFileFunction · 0.85
CopyWithBufferFunction · 0.85
OpenMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.45
ChmodMethod · 0.45
ModeMethod · 0.45

Tested by

no test coverage detected