Make the `analyse` code a bit easier to read.
@@ -106,7 +106,7 @@ func (a *ProjectAnalysis) Analyze(dir string) error {
// init should have the same results.
sort.Sort(dirents)
- var subdirectories []*godirwalk.Dirent
+ var subdirectories []string
// Traverse files
for _, file := range dirents {
@@ -114,26 +114,30 @@ func (a *ProjectAnalysis) Analyze(dir string) error {
continue
}
+ filePath := filepath.Join(dir, file.Name())
+
// If we found a directory, keep track of it until we've gone through all the files first
if file.IsDir() {
- subdirectories = append(subdirectories, file)
+ subdirectories = append(subdirectories, filePath)
continue
}
- filePath := filepath.Join(dir, file.Name())
+ if a.maxFileSize > 0 {
stat, err := os.Stat(filePath)
if err != nil {
// this is highly unexpected but in case there could be a racey situation where
// the file gets removed right between ReadDirents and Stat
continue
}
- if a.maxFileSize > 0 && stat.Size() > a.maxFileSize {
+ if stat.Size() > a.maxFileSize {
logrus.Debugf("skipping %s as it is larger (%d) than max allowed size %d", filePath, stat.Size(), a.maxFileSize)
continue
}
- for _, analyzer := range a.analyzers() {
- // to make skaffold.yaml more portable across OS-es we should generate always / based filePaths
+ }
+
+ // to make skaffold.yaml more portable across OS-es we should always generate / based filePaths
filePath = strings.ReplaceAll(filePath, string(os.PathSeparator), "/")
+ for _, analyzer := range a.analyzers() {
if err := analyzer.analyzeFile(filePath); err != nil {
return err
}
@@ -142,7 +146,7 @@ func (a *ProjectAnalysis) Analyze(dir string) error {
// Recurse into subdirectories
for _, subdir := range subdirectories {
- if err = a.Analyze(filepath.Join(dir, subdir.Name())); err != nil {
+ if err := a.Analyze(subdir); err != nil {
return err
}
}
@@ -150,5 +154,6 @@ func (a *ProjectAnalysis) Analyze(dir string) error {
for _, analyzer := range a.analyzers() {
analyzer.exitDir(dir)
}
+
return nil
}
