Skip to content

Commit

Permalink
Handle errors during snapshotting
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
schmichael committed Nov 13, 2017
1 parent ee063f9 commit 1fd0cba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/allocdir/alloc_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 1fd0cba

Please sign in to comment.