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 <edgar.lee@docker.com>
This commit is contained in:
Edgar Lee 2016-07-13 16:41:51 -07:00 committed by Richard Scothern
parent edd7cb5249
commit 734caef0f4
2 changed files with 45 additions and 5 deletions

View file

@ -25,12 +25,12 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri
return 0, errors.New("no space in slice") return 0, errors.New("no space in slice")
} }
root, err := pathFor(repositoriesRootPathSpec{}) root, errVal := pathFor(repositoriesRootPathSpec{})
if err != nil { if errVal != nil {
return 0, err 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() filePath := fileInfo.Path()
// lop the base path off // lop the base path off
@ -58,7 +58,7 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri
n = copy(repos, foundRepos) n = copy(repos, foundRepos)
// Signal that we have no more entries by setting EOF // 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 errVal = io.EOF
} }

View file

@ -1,6 +1,7 @@
package storage package storage
import ( import (
"fmt"
"io" "io"
"testing" "testing"
@ -123,3 +124,42 @@ func testEq(a, b []string, size int) bool {
} }
return true 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")
}
}