From fdc51bb1f271696f9a3c52592ebb4c74fe64515c Mon Sep 17 00:00:00 2001 From: Edgar Lee Date: Fri, 5 Aug 2016 17:21:48 -0700 Subject: [PATCH] Stop ErrFinishedWalk from escaping from Repositories walk Signed-off-by: Edgar Lee --- registry/storage/catalog.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/registry/storage/catalog.go b/registry/storage/catalog.go index 89616402..5a00f7cd 100644 --- a/registry/storage/catalog.go +++ b/registry/storage/catalog.go @@ -10,11 +10,6 @@ import ( "github.com/docker/distribution/registry/storage/driver" ) -// ErrFinishedWalk is used when the called walk function no longer wants -// to accept any more values. This is used for pagination when the -// required number of repos have been found. -var ErrFinishedWalk = errors.New("finished walk") - // Returns a list, or partial list, of repositories in the registry. // Because it's a quite expensive operation, it should only be used when building up // an initial set of repositories. @@ -30,6 +25,10 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri return 0, err } + // errFinishedWalk signals an early exit to the walk when the current query + // is satisfied. + errFinishedWalk := errors.New("finished walk") + err = Walk(ctx, reg.blobStore.driver, root, func(fileInfo driver.FileInfo) error { filePath := fileInfo.Path() @@ -49,7 +48,7 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri // if we've filled our array, no need to walk any further if len(foundRepos) == len(repos) { - return ErrFinishedWalk + return errFinishedWalk } return nil @@ -57,9 +56,14 @@ 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 == nil || err == ErrSkipDir) { + switch err { + case nil: + // nil means that we completed walk and didn't fill buffer. No more + // records are available. err = io.EOF + case errFinishedWalk: + // more records are available. + err = nil } return n, err