Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Jan 9, 2024
1 parent 40ad281 commit 51bf52c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ func (s *Store) reloadIndex(ctx context.Context) error {
return nil
}

// GC removes garbage from Store. The garbage to be cleaned are:
// GC removes garbage from Store. Unsaved index will be lost. To prevent unexpected
// loss, call SaveIndex() before GC or set AutoSaveIndex to true.
// The garbage to be cleaned are:
// - unreferenced (dangling) blobs in Store which have no predecessors
// - garbage blobs in the storage whose metadata is not stored in Store
func (s *Store) GC(ctx context.Context) error {
Expand Down Expand Up @@ -498,15 +500,15 @@ func (s *Store) GC(ctx context.Context) error {
continue
}
algPath := path.Join(rootpath, alg)
dgstDirs, err := os.ReadDir(algPath)
digestEntries, err := os.ReadDir(algPath)
if err != nil {
return err
}

Check warning on line 506 in content/oci/oci.go

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L505-L506

Added lines #L505 - L506 were not covered by tests
for _, dgstDir := range dgstDirs {
for _, digestEntry := range digestEntries {
if err := isContextDone(ctx); err != nil {
return err
}

Check warning on line 510 in content/oci/oci.go

View check run for this annotation

Codecov / codecov/patch

content/oci/oci.go#L509-L510

Added lines #L509 - L510 were not covered by tests
dgst := dgstDir.Name()
dgst := digestEntry.Name()
blobDigest := digest.NewDigestFromEncoded(digest.Algorithm(alg), dgst)
err := blobDigest.Validate()
// skip irrelevant content
Expand Down
12 changes: 12 additions & 0 deletions content/oci/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3057,3 +3057,15 @@ func equalDescriptorSet(actual []ocispec.Descriptor, expected []ocispec.Descript
}
return true
}

func Test_isContextDone(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
if err := isContextDone(ctx); err != nil {
t.Errorf("expect error = %v, got %v", nil, err)
}
cancel()
if err := isContextDone(ctx); err != context.Canceled {
t.Errorf("expect error = %v, got %v", context.Canceled, err)
}
}

0 comments on commit 51bf52c

Please sign in to comment.