diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index a5f7396897..9e928a46b3 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -143,6 +143,14 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) { // Save the fs state in a map to iterate over later. memFs := map[string]os.FileInfo{} filepath.Walk(s.directory, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if util.IsInWhitelist(path) { + logrus.Infof("Skipping paths under %s, as it is a whitelisted directory", path) + return filepath.SkipDir + } + memFs[path] = info return nil }) @@ -174,7 +182,6 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) { logrus.Debugf("Not adding %s to layer, as it's whitelisted", path) continue } - // Only add to the tar if we add it to the layeredmap. maybeAdd, err := s.l.MaybeAdd(path) if err != nil { diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index a0778bb185..526ac5f50b 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -270,6 +270,15 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { return nil } +func IsInWhitelist(path string) bool { + for _, wl := range whitelist { + if !wl.PrefixMatchOnly && path == wl.Path { + return true + } + } + return false +} + func CheckWhitelist(path string) (bool, error) { abs, err := filepath.Abs(path) if err != nil {