Skip to content

Commit

Permalink
traverse empty subdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfowl committed Feb 28, 2022
1 parent eca1f2f commit 3786a0e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion deplist.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deplist

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -293,9 +294,23 @@ func getDeps(fullPath string) ([]Dependency, Bitmask, error) {
return deps, foundTypes, nil
}

// findBaseDir walks a directory tree through empty subdirs til it finds a directory with content
func findBaseDir(fullPath string) string {
log.Debugf("Checking %s", fullPath)
files, err := ioutil.ReadDir(fullPath)
if err != nil {
log.Fatal(err)
}
if len(files) == 1 && files[0].IsDir() {
return findBaseDir(filepath.Join(fullPath, files[0].Name()))
}
return fullPath
}

// GetDeps scans a given repository and returns all dependencies found in a DependencyList struct.
func GetDeps(fullPath string) ([]Dependency, Bitmask, error) {
log.Debugf("Checking %s", fullPath)
fullPath = findBaseDir(fullPath)

deps, foundTypes, err := getDeps(fullPath)
if err != nil {
return deps, foundTypes, err
Expand Down

0 comments on commit 3786a0e

Please sign in to comment.