2015-07-13 22:08:13 +02:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2015-07-17 20:42:47 +02:00
|
|
|
"errors"
|
|
|
|
"io"
|
2015-07-13 22:08:13 +02:00
|
|
|
"path"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/distribution/context"
|
2015-07-17 20:42:47 +02:00
|
|
|
"github.com/docker/distribution/registry/storage/driver"
|
2015-07-13 22:08:13 +02:00
|
|
|
)
|
|
|
|
|
2015-07-17 20:42:47 +02:00
|
|
|
// Returns a list, or partial list, of repositories in the registry.
|
2015-07-13 22:08:13 +02:00
|
|
|
// Because it's a quite expensive operation, it should only be used when building up
|
|
|
|
// an initial set of repositories.
|
2015-07-17 20:42:47 +02:00
|
|
|
func (reg *registry) Repositories(ctx context.Context, repos []string, last string) (n int, err error) {
|
|
|
|
var foundRepos []string
|
|
|
|
var errVal error
|
|
|
|
|
|
|
|
if len(repos) == 0 {
|
|
|
|
return 0, errors.New("no space in slice")
|
|
|
|
}
|
2015-07-13 22:08:13 +02:00
|
|
|
|
|
|
|
root, err := defaultPathMapper.path(repositoriesRootPathSpec{})
|
|
|
|
if err != nil {
|
2015-07-17 20:42:47 +02:00
|
|
|
return 0, err
|
2015-07-13 22:08:13 +02:00
|
|
|
}
|
|
|
|
|
2015-07-17 20:42:47 +02:00
|
|
|
// Walk each of the directories in our storage. Unfortunately since there's no
|
|
|
|
// guarantee that storage will return files in lexigraphical order, we have
|
|
|
|
// to store everything another slice, sort it and then copy it back to our
|
|
|
|
// passed in slice.
|
|
|
|
|
|
|
|
Walk(ctx, reg.blobStore.driver, root, func(fileInfo driver.FileInfo) error {
|
2015-07-13 22:08:13 +02:00
|
|
|
filePath := fileInfo.Path()
|
|
|
|
|
|
|
|
// lop the base path off
|
|
|
|
repoPath := filePath[len(root)+1:]
|
|
|
|
|
|
|
|
_, file := path.Split(repoPath)
|
|
|
|
if file == "_layers" {
|
|
|
|
repoPath = strings.TrimSuffix(repoPath, "/_layers")
|
2015-07-17 20:42:47 +02:00
|
|
|
if repoPath > last {
|
|
|
|
foundRepos = append(foundRepos, repoPath)
|
2015-07-13 22:08:13 +02:00
|
|
|
}
|
|
|
|
return ErrSkipDir
|
|
|
|
} else if strings.HasPrefix(file, "_") {
|
|
|
|
return ErrSkipDir
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2015-07-17 20:42:47 +02:00
|
|
|
sort.Strings(foundRepos)
|
|
|
|
n = copy(repos, foundRepos)
|
2015-07-13 22:08:13 +02:00
|
|
|
|
2015-07-17 20:42:47 +02:00
|
|
|
// Signal that we have no more entries by setting EOF
|
|
|
|
if len(foundRepos) <= len(repos) {
|
|
|
|
errVal = io.EOF
|
2015-07-13 22:08:13 +02:00
|
|
|
}
|
|
|
|
|
2015-07-17 20:42:47 +02:00
|
|
|
return n, errVal
|
|
|
|
|
2015-07-13 22:08:13 +02:00
|
|
|
}
|