Skip to content

Commit

Permalink
remove cruft and unneeded loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cvgw committed Feb 22, 2020
1 parent 01f6aba commit 2f2914d
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"path/filepath"
"sort"
"strings"
"syscall"

"github.com/GoogleContainerTools/kaniko/pkg/filesystem"
Expand Down Expand Up @@ -136,43 +135,37 @@ func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) {
s.l.Snapshot()

timer := timing.Start("Walking filesystem")
// Save the fs state in a map to iterate over later.
memFs := map[string]*godirwalk.Dirent{}

foundPaths := make([]string, 0)

godirwalk.Walk(s.directory, &godirwalk.Options{
Callback: func(path string, ent *godirwalk.Dirent) error {
if util.IsInWhitelist(path) {
if util.IsDestDir(path) {
logrus.Tracef("Skipping paths under %s, as it is a whitelisted directory", path)

return filepath.SkipDir
}

return nil
}
memFs[path] = ent

foundPaths = append(foundPaths, path)

return nil
},
Unsorted: true,
},
)
timing.DefaultRun.Stop(timer)

filesToResolve := make([]string, 0, len(memFs))
for file := range memFs {
if strings.HasPrefix(file, "/tmp/dir") {
logrus.Infof("found %s", file)
}
filesToResolve = append(filesToResolve, file)
}

resolvedFiles, err := filesystem.ResolvePaths(filesToResolve, s.whitelist)
resolvedFiles, err := filesystem.ResolvePaths(foundPaths, s.whitelist)
if err != nil {
return nil, nil, err
}

resolvedMemFs := make(map[string]bool)
for _, f := range resolvedFiles {
if strings.HasPrefix(f, "/tmp/dir") {
logrus.Infof("found again %s", f)
}
resolvedMemFs[f] = true
}

Expand Down

0 comments on commit 2f2914d

Please sign in to comment.