mirror of
https://github.com/distribution/distribution.git
synced 2025-07-17 08:53:54 +00:00
skip invalid link path during gc
Signed-off-by: Liang Zheng <zhengliang0901@gmail.com>
This commit is contained in:
parent
10d90f7290
commit
f1fb006795
@ -458,6 +458,42 @@ func TestGCWithUnusedLayerLinkPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGCWithInvalidRevisionLinkFile(t *testing.T) {
|
||||||
|
ctx := dcontext.Background()
|
||||||
|
d := inmemory.New()
|
||||||
|
|
||||||
|
registry := createRegistry(t, d)
|
||||||
|
repo := makeRepository(t, registry, "invalidlinkfile")
|
||||||
|
image := uploadRandomSchema2Image(t, repo)
|
||||||
|
|
||||||
|
err := repo.Tags(ctx).Tag(ctx, "image", distribution.Descriptor{Digest: image.manifestDigest})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to tag descriptor: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate a missing _manifests/tags directory
|
||||||
|
revisionLinkPath, err := pathFor(manifestRevisionLinkPathSpec{
|
||||||
|
name: "invalidlinkfile",
|
||||||
|
revision: image.manifestDigest,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = d.PutContent(ctx, revisionLinkPath, []byte("invalid digest"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = MarkAndSweep(dcontext.Background(), d, registry, GCOpts{
|
||||||
|
DryRun: false,
|
||||||
|
RemoveUntagged: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("got error: %v, expected nil", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGCWithUnknownRepository(t *testing.T) {
|
func TestGCWithUnknownRepository(t *testing.T) {
|
||||||
ctx := dcontext.Background()
|
ctx := dcontext.Background()
|
||||||
d := inmemory.New()
|
d := inmemory.New()
|
||||||
|
@ -246,13 +246,17 @@ func (lbs *linkedBlobStore) Enumerate(ctx context.Context, ingestor func(digest.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read the digest found in link
|
// read the digest found in link
|
||||||
digest, err := lbs.blobStore.readlink(ctx, filePath)
|
dgst, err := lbs.blobStore.readlink(ctx, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == digest.ErrDigestInvalidFormat {
|
||||||
|
dcontext.GetLogger(ctx).Warnf("invalid link file %s", filePath)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure this conforms to the linkPathFns
|
// ensure this conforms to the linkPathFns
|
||||||
_, err = lbs.Stat(ctx, digest)
|
_, err = lbs.Stat(ctx, dgst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// we expect this error to occur so we move on
|
// we expect this error to occur so we move on
|
||||||
if err == distribution.ErrBlobUnknown {
|
if err == distribution.ErrBlobUnknown {
|
||||||
@ -261,7 +265,7 @@ func (lbs *linkedBlobStore) Enumerate(ctx context.Context, ingestor func(digest.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ingestor(digest)
|
err = ingestor(dgst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user