MCPcopy Index your code
hub / github.com/devspace-sh/devspace / Copy

Function Copy

pkg/util/fsutil/filesystem.go:67–108  ·  view source on GitHub ↗

Copy copies a file to a destination path

(sourcePath string, targetPath string, overwrite bool)

Source from the content-addressed store, hash-verified

65
66// Copy copies a file to a destination path
67func Copy(sourcePath string, targetPath string, overwrite bool) error {
68 if overwrite {
69 return recursiveCopy.Copy(sourcePath, targetPath)
70 }
71
72 var err error
73
74 // Convert to absolute path
75 sourcePath, err = filepath.Abs(sourcePath)
76 if err != nil {
77 return err
78 }
79
80 // Convert to absolute path
81 targetPath, err = filepath.Abs(targetPath)
82 if err != nil {
83 return err
84 }
85
86 return filepath.Walk(sourcePath, func(nextSourcePath string, fileInfo os.FileInfo, err error) error {
87 nextTargetPath := filepath.Join(targetPath, strings.TrimPrefix(nextSourcePath, sourcePath))
88 if fileInfo == nil {
89 return nil
90 }
91
92 if !fileInfo.Mode().IsRegular() {
93 return nil
94 }
95
96 if fileInfo.IsDir() {
97 _ = os.MkdirAll(nextTargetPath, os.ModePerm)
98 return Copy(nextSourcePath, nextTargetPath, overwrite)
99 }
100
101 _, statErr := os.Stat(nextTargetPath)
102 if statErr != nil {
103 return recursiveCopy.Copy(nextSourcePath, nextTargetPath)
104 }
105
106 return nil
107 })
108}

Callers 5

CopyTemplatesMethod · 0.92
CopyFileMethod · 0.92
CreateDockerfileMethod · 0.92
TestSaveLoadKubeConfigFunction · 0.92
TestCopyFunction · 0.85

Calls 3

CopyMethod · 0.65
ModeMethod · 0.45
IsDirMethod · 0.45

Tested by 2

TestSaveLoadKubeConfigFunction · 0.74
TestCopyFunction · 0.68