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

Function CopyDir

pkg/utils/file.go:45–74  ·  view source on GitHub ↗

CopyDir Dir copies a whole directory recursively

(src, dst string)

Source from the content-addressed store, hash-verified

43
44// CopyDir Dir copies a whole directory recursively
45func CopyDir(src, dst string) error {
46 var err error
47 var fds []os.DirEntry
48 var srcinfo os.FileInfo
49
50 if srcinfo, err = os.Stat(src); err != nil {
51 return err
52 }
53 if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
54 return err
55 }
56 if fds, err = os.ReadDir(src); err != nil {
57 return err
58 }
59 for _, fd := range fds {
60 srcfp := path.Join(src, fd.Name())
61 dstfp := path.Join(dst, fd.Name())
62
63 if fd.IsDir() {
64 if err = CopyDir(srcfp, dstfp); err != nil {
65 fmt.Println(err)
66 }
67 } else {
68 if err = CopyFile(srcfp, dstfp); err != nil {
69 fmt.Println(err)
70 }
71 }
72 }
73 return nil
74}
75
76// SymlinkOrCopyFile symlinks a file or copy if symlink failed
77func SymlinkOrCopyFile(src, dst string) error {

Callers

nothing calls this directly

Calls 7

CopyFileFunction · 0.70
NameMethod · 0.65
IsDirMethod · 0.65
StatMethod · 0.45
MkdirAllMethod · 0.45
ModeMethod · 0.45
ReadDirMethod · 0.45

Tested by

no test coverage detected