storage: correctly handle error during Walk
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
c0d094a72a
commit
7bf8f846c2
2 changed files with 12 additions and 4 deletions
|
@ -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
|
||||||
|
|
|
@ -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,8 +54,12 @@ 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 {
|
||||||
t.Error(err.Error())
|
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 {
|
err = Walk(ctx, d, "/nonexistant", func(fileInfo driver.FileInfo) error {
|
||||||
|
|
Loading…
Reference in a new issue