diff --git a/content/oci/oci.go b/content/oci/oci.go index bcfdec20..e2b3d86c 100644 --- a/content/oci/oci.go +++ b/content/oci/oci.go @@ -465,6 +465,9 @@ func (s *Store) traverseIndex(ctx context.Context) (set.Set[digest.Digest], erro queue := []ocispec.Descriptor{} queue = append(queue, manifests...) for len(queue) > 0 { + if err := isContextDone(ctx); err != nil { + return nil, err + } head := queue[0] queue = queue[1:] if visited.Contains(head.Digest) { @@ -521,6 +524,9 @@ func (s *Store) GC(ctx context.Context) error { return err } for _, dgstDir := range dgstDirs { + if err := isContextDone(ctx); err != nil { + return err + } dgst := dgstDir.Name() blobDigest := digest.NewDigestFromEncoded(digest.Algorithm(alg), dgst) err := blobDigest.Validate() diff --git a/content/oci/oci_test.go b/content/oci/oci_test.go index aacd19f0..c4af37a2 100644 --- a/content/oci/oci_test.go +++ b/content/oci/oci_test.go @@ -2914,20 +2914,11 @@ func TestStore_GC(t *testing.T) { generateManifest(descs[0], &descs[13], descs[1]) // Blob 16, referrer of a garbage manifest // push blobs 0 - blobs 10 into s - eg, egCtx := errgroup.WithContext(ctx) for i := 0; i <= 10; i++ { - eg.Go(func(i int) func() error { - return func() error { - err := s.Push(egCtx, descs[i], bytes.NewReader(blobs[i])) - if err != nil { - return fmt.Errorf("failed to push test content to src: %d: %v", i, err) - } - return nil - } - }(i)) - } - if err := eg.Wait(); err != nil { - t.Fatal(err) + err := s.Push(ctx, descs[i], bytes.NewReader(blobs[i])) + if err != nil { + t.Errorf("failed to push test content to src: %d: %v", i, err) + } } // remove blobs 4 - blobs 10 from index.json @@ -2939,23 +2930,15 @@ func TestStore_GC(t *testing.T) { // push blobs 11 - blobs 16 into s.storage, making them garbage as their metadata // doesn't exist in s for i := 11; i < len(blobs); i++ { - eg.Go(func(i int) func() error { - return func() error { - err := s.storage.Push(egCtx, descs[i], bytes.NewReader(blobs[i])) - if err != nil { - return fmt.Errorf("failed to push test content to src: %d: %v", i, err) - } - return nil - } - }(i)) - } - if err := eg.Wait(); err != nil { - t.Fatal(err) + err := s.storage.Push(ctx, descs[i], bytes.NewReader(blobs[i])) + if err != nil { + t.Errorf("failed to push test content to src: %d: %v", i, err) + } } // confirm that all the blobs are in the storage for i := 11; i < len(blobs); i++ { - exists, err := s.Exists(egCtx, descs[i]) + exists, err := s.Exists(ctx, descs[i]) if err != nil { t.Fatal(err) } @@ -2965,14 +2948,14 @@ func TestStore_GC(t *testing.T) { } // perform GC - if err = s.GC(egCtx); err != nil { + if err = s.GC(ctx); err != nil { t.Fatal(err) } // verify existence wantExistence := []bool{true, true, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false} for i, wantValue := range wantExistence { - exists, err := s.Exists(egCtx, descs[i]) + exists, err := s.Exists(ctx, descs[i]) if err != nil { t.Fatal(err) }