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

Method WalkAppFiles

cf/appfiles/app_files.go:175–212  ·  view source on GitHub ↗
(dir string, onEachFile func(string, string) error)

Source from the content-addressed store, hash-verified

173}
174
175func (appfiles ApplicationFiles) WalkAppFiles(dir string, onEachFile func(string, string) error) error {
176 cfIgnore := loadIgnoreFile(dir)
177 walkFunc := func(fullPath string, f os.FileInfo, err error) error {
178 fileRelativePath, _ := filepath.Rel(dir, fullPath)
179 fileRelativeUnixPath := filepath.ToSlash(fileRelativePath)
180
181 if err != nil && runtime.GOOS == "windows" {
182 f, err = os.Lstat(windowsPathPrefix + fullPath)
183 if err != nil {
184 return err
185 }
186 fullPath = windowsPathPrefix + fullPath
187 }
188
189 if fullPath == dir {
190 return nil
191 }
192
193 if cfIgnore.FileShouldBeIgnored(fileRelativeUnixPath) {
194 if err == nil && f.IsDir() {
195 return filepath.SkipDir
196 }
197 return nil
198 }
199
200 if err != nil {
201 return err
202 }
203
204 if !f.Mode().IsRegular() && !f.IsDir() {
205 return nil
206 }
207
208 return onEachFile(fileRelativePath, fullPath)
209 }
210
211 return filepath.Walk(dir, walkFunc)
212}
213
214func loadIgnoreFile(dir string) CfIgnore {
215 fileContents, err := ioutil.ReadFile(filepath.Join(dir, ".cfignore"))

Callers 3

AppFilesInDirMethod · 0.95
CountFilesMethod · 0.95
writeZipFileFunction · 0.95

Calls 4

loadIgnoreFileFunction · 0.85
IsDirMethod · 0.80
ModeMethod · 0.80
FileShouldBeIgnoredMethod · 0.65

Tested by

no test coverage detected