(dir string, onEachFile func(string, string) error)
| 173 | } |
| 174 | |
| 175 | func (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 | |
| 214 | func loadIgnoreFile(dir string) CfIgnore { |
| 215 | fileContents, err := ioutil.ReadFile(filepath.Join(dir, ".cfignore")) |
no test coverage detected