From 734caef0f4560d7aa71502a206514a641b45d94b Mon Sep 17 00:00:00 2001 From: Edgar Lee Date: Wed, 13 Jul 2016 16:41:51 -0700 Subject: [PATCH] Fix storage drivers dropping non EOF errors when listing repositories This fixes errors other than io.EOF from being dropped when a storage driver lists repositories. For example, filesystem driver may point to a missing directory and errors, which then gets subsequently dropped. Signed-off-by: Edgar Lee --- registry/storage/catalog.go | 10 ++++---- registry/storage/catalog_test.go | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/registry/storage/catalog.go b/registry/storage/catalog.go index 3b13b7ad1..51f316917 100644 --- a/registry/storage/catalog.go +++ b/registry/storage/catalog.go @@ -25,12 +25,12 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri return 0, errors.New("no space in slice") } - root, err := pathFor(repositoriesRootPathSpec{}) - if err != nil { - return 0, err + root, errVal := pathFor(repositoriesRootPathSpec{}) + if errVal != nil { + return 0, errVal } - err = Walk(ctx, reg.blobStore.driver, root, func(fileInfo driver.FileInfo) error { + errVal = Walk(ctx, reg.blobStore.driver, root, func(fileInfo driver.FileInfo) error { filePath := fileInfo.Path() // lop the base path off @@ -58,7 +58,7 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri n = copy(repos, foundRepos) // Signal that we have no more entries by setting EOF - if len(foundRepos) <= len(repos) && err != ErrFinishedWalk { + if len(foundRepos) <= len(repos) && (errVal == nil || errVal == ErrSkipDir) { errVal = io.EOF } diff --git a/registry/storage/catalog_test.go b/registry/storage/catalog_test.go index eb062c5b7..40fa909d7 100644 --- a/registry/storage/catalog_test.go +++ b/registry/storage/catalog_test.go @@ -1,6 +1,7 @@ package storage import ( + "fmt" "io" "testing" @@ -123,3 +124,42 @@ func testEq(a, b []string, size int) bool { } return true } + +func setupBadWalkEnv(t *testing.T) *setupEnv { + d := newBadListDriver() + ctx := context.Background() + registry, err := NewRegistry(ctx, d, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableRedirect) + if err != nil { + t.Fatalf("error creating registry: %v", err) + } + + return &setupEnv{ + ctx: ctx, + driver: d, + registry: registry, + } +} + +type badListDriver struct { + driver.StorageDriver +} + +var _ driver.StorageDriver = &badListDriver{} + +func newBadListDriver() *badListDriver { + return &badListDriver{StorageDriver: inmemory.New()} +} + +func (d *badListDriver) List(ctx context.Context, path string) ([]string, error) { + return nil, fmt.Errorf("List error") +} + +func TestCatalogWalkError(t *testing.T) { + env := setupBadWalkEnv(t) + p := make([]string, 1) + + _, err := env.registry.Repositories(env.ctx, p, "") + if err == io.EOF { + t.Errorf("Expected catalog driver list error") + } +}