diff --git a/registry/storage/walk.go b/registry/storage/walk.go index 3d8912765..a27c2b032 100644 --- a/registry/storage/walk.go +++ b/registry/storage/walk.go @@ -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 diff --git a/registry/storage/walk_test.go b/registry/storage/walk_test.go index 40b8547cf..684155b21 100644 --- a/registry/storage/walk_test.go +++ b/registry/storage/walk_test.go @@ -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 {