MCPcopy Create free account
hub / github.com/MertJSX/folderhost / CopyDirectory

Function CopyDirectory

utils/copy_functions.go:10–49  ·  view source on GitHub ↗
(srcDir, dest string)

Source from the content-addressed store, hash-verified

8)
9
10func CopyDirectory(srcDir, dest string) error {
11 if err := CreateIfNotExists(dest, 0755); err != nil {
12 return err
13 }
14
15 entries, err := os.ReadDir(srcDir)
16 if err != nil {
17 return err
18 }
19
20 for _, entry := range entries {
21 sourcePath := filepath.Join(srcDir, entry.Name())
22 destPath := filepath.Join(dest, entry.Name())
23
24 fileInfo, err := os.Stat(sourcePath)
25 if err != nil {
26 return err
27 }
28
29 switch fileInfo.Mode() & os.ModeType {
30 case os.ModeDir:
31 if err := CopyDirectory(sourcePath, destPath); err != nil {
32 return err
33 }
34 case os.ModeSymlink:
35 if err := CopySymLink(sourcePath, destPath); err != nil {
36 return err
37 }
38 default:
39 if err := CopyFile(sourcePath, destPath); err != nil {
40 return err
41 }
42 }
43
44 if err := os.Chmod(destPath, fileInfo.Mode()); err != nil {
45 return err
46 }
47 }
48 return nil
49}
50
51func CopyFile(srcFile, dstFile string) error {
52 out, err := os.Create(dstFile)

Callers 1

CreateCopyFunction · 0.92

Calls 3

CreateIfNotExistsFunction · 0.85
CopySymLinkFunction · 0.85
CopyFileFunction · 0.85

Tested by

no test coverage detected