Make snapshotting faster by using filepath.SkipDir. (#451)
filepath.Walk has a special error you can return from your walkFn indicating it should skip directories. This change makes use of that to skip whitelisted directories.
This commit is contained in:
parent
f99e5f5c6d
commit
0c294138b8
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue