MCPcopy
hub / github.com/filebrowser/filebrowser / CopyDir

Function CopyDir

fileutils/dir.go:13–63  ·  view source on GitHub ↗

CopyDir copies a directory from source to dest and all of its sub-directories. It doesn't stop if it finds an error during the copy. Returns an error if any.

(afs afero.Fs, source, dest string, fileMode, dirMode fs.FileMode)

Source from the content-addressed store, hash-verified

11// of its sub-directories. It doesn't stop if it finds an error
12// during the copy. Returns an error if any.
13func CopyDir(afs afero.Fs, source, dest string, fileMode, dirMode fs.FileMode) error {
14 // Get properties of source.
15 srcinfo, err := afs.Stat(source)
16 if err != nil {
17 return err
18 }
19
20 // Create the destination directory.
21 err = afs.MkdirAll(dest, srcinfo.Mode())
22 if err != nil {
23 return err
24 }
25
26 dir, _ := afs.Open(source)
27 obs, err := dir.Readdir(-1)
28 if err != nil {
29 return err
30 }
31
32 var errs []error
33
34 for _, obj := range obs {
35 fsource := source + "/" + obj.Name()
36 fdest := dest + "/" + obj.Name()
37
38 if obj.IsDir() {
39 // Create sub-directories, recursively.
40 err = CopyDir(afs, fsource, fdest, fileMode, dirMode)
41 if err != nil {
42 errs = append(errs, err)
43 }
44 } else {
45 // Perform the file copy.
46 err = CopyFile(afs, fsource, fdest, fileMode, dirMode)
47 if err != nil {
48 errs = append(errs, err)
49 }
50 }
51 }
52
53 var errString string
54 for _, err := range errs {
55 errString += err.Error() + "\n"
56 }
57
58 if errString != "" {
59 return errors.New(errString)
60 }
61
62 return nil
63}

Callers 1

CopyFunction · 0.85

Calls 7

CopyFileFunction · 0.85
MkdirAllMethod · 0.80
ReaddirMethod · 0.80
NameMethod · 0.80
ErrorMethod · 0.80
StatMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected