storage: correctly handle error during Walk

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-12-01 16:24:07 -08:00
parent 329c353411
commit 6ad10796ef
2 changed files with 12 additions and 4 deletions

View file

@ -38,7 +38,9 @@ func Walk(ctx context.Context, driver storageDriver.StorageDriver, from string,
}
if fileInfo.IsDir() && !skipDir {
Walk(ctx, driver, child, f)
if err := Walk(ctx, driver, child, f); err != nil {
return err
}
}
}
return nil

View file

@ -41,10 +41,12 @@ func TestWalkErrors(t *testing.T) {
t.Error("Expected invalid root err")
}
errEarlyExpected := fmt.Errorf("Early termination")
err = Walk(ctx, d, "/", func(fileInfo driver.FileInfo) error {
// error on the 2nd file
if fileInfo.Path() == "/a/b" {
return fmt.Errorf("Early termination")
return errEarlyExpected
}
delete(expected, fileInfo.Path())
return nil
@ -52,8 +54,12 @@ func TestWalkErrors(t *testing.T) {
if len(expected) != fileCount-1 {
t.Error("Walk failed to terminate with error")
}
if err != nil {
t.Error(err.Error())
if err != errEarlyExpected {
if err == nil {
t.Fatalf("expected an error due to early termination")
} else {
t.Error(err.Error())
}
}
err = Walk(ctx, d, "/nonexistant", func(fileInfo driver.FileInfo) error {