forked from TrueCloudLab/distribution
Merge pull request #1887 from hinshun/fix-catalog-enumerate
Stop ErrFinishedWalk from escaping from Repositories walk
This commit is contained in:
commit
c270829c6e
2 changed files with 13 additions and 10 deletions
|
@ -9,7 +9,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/docker/distribution/registry/api/errcode"
|
"github.com/docker/distribution/registry/api/errcode"
|
||||||
"github.com/docker/distribution/registry/storage"
|
|
||||||
"github.com/docker/distribution/registry/storage/driver"
|
"github.com/docker/distribution/registry/storage/driver"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
)
|
)
|
||||||
|
@ -51,7 +50,7 @@ func (ch *catalogHandler) GetCatalog(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err == io.EOF || pathNotFound {
|
if err == io.EOF || pathNotFound {
|
||||||
moreEntries = false
|
moreEntries = false
|
||||||
} else if err != nil && err != storage.ErrFinishedWalk {
|
} else if err != nil {
|
||||||
ch.Errors = append(ch.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
ch.Errors = append(ch.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,6 @@ import (
|
||||||
"github.com/docker/distribution/registry/storage/driver"
|
"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.
|
// 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
|
// Because it's a quite expensive operation, it should only be used when building up
|
||||||
// an initial set of repositories.
|
// an initial set of repositories.
|
||||||
|
@ -30,6 +25,10 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri
|
||||||
return 0, err
|
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 {
|
err = Walk(ctx, reg.blobStore.driver, root, func(fileInfo driver.FileInfo) error {
|
||||||
filePath := fileInfo.Path()
|
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 we've filled our array, no need to walk any further
|
||||||
if len(foundRepos) == len(repos) {
|
if len(foundRepos) == len(repos) {
|
||||||
return ErrFinishedWalk
|
return errFinishedWalk
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -57,9 +56,14 @@ 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
|
switch err {
|
||||||
if len(foundRepos) <= len(repos) && (err == nil || err == ErrSkipDir) {
|
case nil:
|
||||||
|
// nil means that we completed walk and didn't fill buffer. No more
|
||||||
|
// records are available.
|
||||||
err = io.EOF
|
err = io.EOF
|
||||||
|
case errFinishedWalk:
|
||||||
|
// more records are available.
|
||||||
|
err = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return n, err
|
return n, err
|
||||||
|
|
Loading…
Reference in a new issue