Handle errors during snapshotting

If an alloc dir is being GC'd (removed) during snapshotting the walk
func will be passed an error. Previously we didn't check for an error so
a panic would occur when we'd try to use a nil `fileInfo`.
This commit is contained in:
Michael Schurter 2017-11-06 11:26:29 -08:00
parent ec15b90d3a
commit 23c66e37c5
1 changed files with 5 additions and 1 deletions

View File

@ -139,6 +139,10 @@ func (d *AllocDir) Snapshot(w io.Writer) error {
defer tw.Close()
walkFn := func(path string, fileInfo os.FileInfo, err error) error {
if err != nil {
return err
}
// Include the path of the file name relative to the alloc dir
// so that we can put the files in the right directories
relPath, err := filepath.Rel(d.AllocDir, path)
@ -182,7 +186,7 @@ func (d *AllocDir) Snapshot(w io.Writer) error {
// directories in the archive
for _, path := range rootPaths {
if err := filepath.Walk(path, walkFn); err != nil {
return err
return fmt.Errorf("failed to snapshot %s: %v", path, err)
}
}