MCPcopy Create free account
hub / github.com/AdRoll/baker / CopyDirectory

Function CopyDirectory

testutil/dir.go:10–49  ·  view source on GitHub ↗
(scrDir, dest string)

Source from the content-addressed store, hash-verified

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

Calls 2

CreateIfNotExistsFunction · 0.85
CopyFunction · 0.85