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 c0d094a72a
commit 7bf8f846c2
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 { if fileInfo.IsDir() && !skipDir {
Walk(ctx, driver, child, f) if err := Walk(ctx, driver, child, f); err != nil {
return err
}
} }
} }
return nil return nil

View file

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