mirror of
https://github.com/distribution/distribution.git
synced 2025-07-16 08:27:36 +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) {
|
||||
ctx := dcontext.Background()
|
||||
d := inmemory.New()
|
||||
|
@ -246,13 +246,17 @@ func (lbs *linkedBlobStore) Enumerate(ctx context.Context, ingestor func(digest.
|
||||
}
|
||||
|
||||
// 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 == digest.ErrDigestInvalidFormat {
|
||||
dcontext.GetLogger(ctx).Warnf("invalid link file %s", filePath)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ensure this conforms to the linkPathFns
|
||||
_, err = lbs.Stat(ctx, digest)
|
||||
_, err = lbs.Stat(ctx, dgst)
|
||||
if err != nil {
|
||||
// we expect this error to occur so we move on
|
||||
if err == distribution.ErrBlobUnknown {
|
||||
@ -261,7 +265,7 @@ func (lbs *linkedBlobStore) Enumerate(ctx context.Context, ingestor func(digest.
|
||||
return err
|
||||
}
|
||||
|
||||
err = ingestor(digest)
|
||||
err = ingestor(dgst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user