Simplify snapshotting. (#517)
This commit is contained in:
parent
9d10516698
commit
9ab66560db
|
|
@ -77,34 +77,34 @@ func (s *Snapshotter) TakeSnapshot(files []string) (string, error) {
|
||||||
defer t.Close()
|
defer t.Close()
|
||||||
|
|
||||||
// First add to the tar any parent directories that haven't been added
|
// First add to the tar any parent directories that haven't been added
|
||||||
parentDirs := []string{}
|
parentDirs := map[string]struct{}{}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
parents := util.ParentDirectories(file)
|
for _, p := range util.ParentDirectories(file) {
|
||||||
parentDirs = append(parentDirs, parents...)
|
parentDirs[p] = struct{}{}
|
||||||
}
|
|
||||||
for _, file := range parentDirs {
|
|
||||||
file = filepath.Clean(file)
|
|
||||||
if val, ok := snapshottedFiles[file]; ok && val {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for file := range parentDirs {
|
||||||
|
file = filepath.Clean(file)
|
||||||
snapshottedFiles[file] = true
|
snapshottedFiles[file] = true
|
||||||
|
|
||||||
|
// The parent directory might already be in a previous layer.
|
||||||
fileAdded, err := s.l.MaybeAdd(file)
|
fileAdded, err := s.l.MaybeAdd(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Unable to add parent dir %s to layered map: %s", file, err)
|
return "", fmt.Errorf("Unable to add parent dir %s to layered map: %s", file, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileAdded {
|
if fileAdded {
|
||||||
err = t.AddFileToTar(file)
|
if err = t.AddFileToTar(file); err != nil {
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("Error adding parent dir %s to tar: %s", file, err)
|
return "", fmt.Errorf("Error adding parent dir %s to tar: %s", file, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next add the files themselves to the tar
|
// Next add the files themselves to the tar
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
// We might have already added the file above as a parent directory of another file.
|
||||||
file = filepath.Clean(file)
|
file = filepath.Clean(file)
|
||||||
if val, ok := snapshottedFiles[file]; ok && val {
|
if _, ok := snapshottedFiles[file]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
snapshottedFiles[file] = true
|
snapshottedFiles[file] = true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue