MCPcopy
hub / github.com/cloudfoundry/cli / CopyFiles

Method CopyFiles

cf/appfiles/app_files.go:84–136  ·  view source on GitHub ↗
(appFiles []models.AppFileFields, fromDir, toDir string)

Source from the content-addressed store, hash-verified

82}
83
84func (appfiles ApplicationFiles) CopyFiles(appFiles []models.AppFileFields, fromDir, toDir string) error {
85 for _, file := range appFiles {
86 err := func() error {
87 path, err := securejoin.SecureJoin(fromDir, file.Path)
88 if err != nil {
89 return err
90 }
91
92 fromPath, err := filepath.Abs(path)
93 if err != nil {
94 return err
95 }
96
97 if runtime.GOOS == "windows" {
98 fromPath = windowsPathPrefix + fromPath
99 }
100
101 srcFileInfo, err := os.Stat(fromPath)
102 if err != nil {
103 return err
104 }
105
106 path, err = securejoin.SecureJoin(toDir, file.Path)
107 if err != nil {
108 return err
109 }
110 toPath, err := filepath.Abs(path)
111 if err != nil {
112 return err
113 }
114
115 if runtime.GOOS == "windows" {
116 toPath = windowsPathPrefix + toPath
117 }
118
119 if srcFileInfo.IsDir() {
120 err = os.MkdirAll(toPath, srcFileInfo.Mode())
121 if err != nil {
122 return err
123 }
124 return nil
125 }
126
127 return appfiles.copyFile(fromPath, toPath, srcFileInfo.Mode())
128 }()
129
130 if err != nil {
131 return err
132 }
133 }
134
135 return nil
136}
137
138func (appfiles ApplicationFiles) copyFile(srcPath string, dstPath string, fileMode os.FileMode) error {
139 dst, err := fileutils.Create(dstPath)

Callers

nothing calls this directly

Calls 3

copyFileMethod · 0.95
IsDirMethod · 0.80
ModeMethod · 0.80

Tested by

no test coverage detected