forked from TrueCloudLab/distribution
commit
c2a201dabf
2 changed files with 43 additions and 4 deletions
|
@ -39,7 +39,7 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri
|
||||||
_, file := path.Split(repoPath)
|
_, file := path.Split(repoPath)
|
||||||
if file == "_layers" {
|
if file == "_layers" {
|
||||||
repoPath = strings.TrimSuffix(repoPath, "/_layers")
|
repoPath = strings.TrimSuffix(repoPath, "/_layers")
|
||||||
if repoPath > last {
|
if pathGreaterThan(repoPath, last) {
|
||||||
foundRepos = append(foundRepos, repoPath)
|
foundRepos = append(foundRepos, repoPath)
|
||||||
}
|
}
|
||||||
return ErrSkipDir
|
return ErrSkipDir
|
||||||
|
@ -95,3 +95,23 @@ func (reg *registry) Enumerate(ctx context.Context, ingester func(string) error)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pathGreaterThan(pathX, pathY string) (b bool) {
|
||||||
|
splitPathX := strings.SplitN(pathX, "/", 2)
|
||||||
|
splitPathY := strings.SplitN(pathY, "/", 2)
|
||||||
|
|
||||||
|
if splitPathX[0] == splitPathY[0] {
|
||||||
|
if len(splitPathX) == 1 && len(splitPathY) == 1 {
|
||||||
|
return false
|
||||||
|
} else if len(splitPathX) == 1 && len(splitPathY) != 1 {
|
||||||
|
return false
|
||||||
|
} else if len(splitPathX) != 1 && len(splitPathY) == 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathGreaterThan(splitPathX[1], splitPathY[1])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return splitPathX[0] > splitPathY[0]
|
||||||
|
}
|
||||||
|
|
|
@ -33,9 +33,13 @@ func setupFS(t *testing.T) *setupEnv {
|
||||||
repos := []string{
|
repos := []string{
|
||||||
"foo/a",
|
"foo/a",
|
||||||
"foo/b",
|
"foo/b",
|
||||||
|
"foo-bar/a",
|
||||||
"bar/c",
|
"bar/c",
|
||||||
"bar/d",
|
"bar/d",
|
||||||
|
"bar/e",
|
||||||
"foo/d/in",
|
"foo/d/in",
|
||||||
|
"foo-bar/b",
|
||||||
|
"test",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
|
@ -45,9 +49,13 @@ func setupFS(t *testing.T) *setupEnv {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"bar/c",
|
"bar/c",
|
||||||
"bar/d",
|
"bar/d",
|
||||||
|
"bar/e",
|
||||||
"foo/a",
|
"foo/a",
|
||||||
"foo/b",
|
"foo/b",
|
||||||
"foo/d/in",
|
"foo/d/in",
|
||||||
|
"foo-bar/a",
|
||||||
|
"foo-bar/b",
|
||||||
|
"test",
|
||||||
}
|
}
|
||||||
|
|
||||||
return &setupEnv{
|
return &setupEnv{
|
||||||
|
@ -118,7 +126,7 @@ func TestCatalog(t *testing.T) {
|
||||||
func TestCatalogInParts(t *testing.T) {
|
func TestCatalogInParts(t *testing.T) {
|
||||||
env := setupFS(t)
|
env := setupFS(t)
|
||||||
|
|
||||||
chunkLen := 2
|
chunkLen := 3
|
||||||
p := make([]string, chunkLen)
|
p := make([]string, chunkLen)
|
||||||
|
|
||||||
numFilled, err := env.registry.Repositories(env.ctx, p, "")
|
numFilled, err := env.registry.Repositories(env.ctx, p, "")
|
||||||
|
@ -144,12 +152,23 @@ func TestCatalogInParts(t *testing.T) {
|
||||||
lastRepo = p[len(p)-1]
|
lastRepo = p[len(p)-1]
|
||||||
numFilled, err = env.registry.Repositories(env.ctx, p, lastRepo)
|
numFilled, err = env.registry.Repositories(env.ctx, p, lastRepo)
|
||||||
|
|
||||||
|
if err != io.EOF || numFilled != len(p) {
|
||||||
|
t.Errorf("Expected end of catalog")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !testEq(p, env.expected[chunkLen*2:chunkLen*3], numFilled) {
|
||||||
|
t.Errorf("Expected catalog third chunk err")
|
||||||
|
}
|
||||||
|
|
||||||
|
lastRepo = p[len(p)-1]
|
||||||
|
numFilled, err = env.registry.Repositories(env.ctx, p, lastRepo)
|
||||||
|
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
t.Errorf("Catalog has more values which we aren't expecting")
|
t.Errorf("Catalog has more values which we aren't expecting")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !testEq(p, env.expected[chunkLen*2:chunkLen*3-1], numFilled) {
|
if numFilled != 0 {
|
||||||
t.Errorf("Expected catalog third chunk err")
|
t.Errorf("Expected catalog fourth chunk err")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue