Skip to content

Commit

Permalink
added the Store field GCEnabled
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Dec 7, 2023
1 parent 2795dd7 commit 5b4e998
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 174 deletions.
38 changes: 25 additions & 13 deletions content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ type Store struct {
// to manually call SaveIndex() when needed.
// - Default value: true.
AutoSaveIndex bool
root string
indexPath string
index *ocispec.Index
storage *Storage
tagResolver *resolver.Memory
graph *graph.Memory

// AutoGarbageCollection controls if the OCI store will automatically clean
// dangling nodes during Delete() operation.
// - If AutoGarbageCollection is set to false, it's the user's responsibility
// to manually delete the dangling nodes.
// - Default value: true.
AutoGarbageCollection bool

root string
indexPath string
index *ocispec.Index
storage *Storage
tagResolver *resolver.Memory
graph *graph.Memory

// sync ensures that most operations can be done concurrently, while Delete
// has the exclusive access to Store if a delete operation is underway. Operations
Expand All @@ -84,12 +92,13 @@ func NewWithContext(ctx context.Context, root string) (*Store, error) {
}

store := &Store{
AutoSaveIndex: true,
root: rootAbs,
indexPath: filepath.Join(rootAbs, ocispec.ImageIndexFile),
storage: storage,
tagResolver: resolver.NewMemory(),
graph: graph.NewMemory(),
AutoSaveIndex: true,
AutoGarbageCollection: true,
root: rootAbs,
indexPath: filepath.Join(rootAbs, ocispec.ImageIndexFile),
storage: storage,
tagResolver: resolver.NewMemory(),
graph: graph.NewMemory(),
}

if err := ensureDir(filepath.Join(rootAbs, ocispec.ImageBlobsDir)); err != nil {
Expand Down Expand Up @@ -170,7 +179,10 @@ func (s *Store) doDelete(ctx context.Context, target ocispec.Descriptor) error {
if err := s.storage.Delete(ctx, target); err != nil {
return err
}
return s.doGarbageCollection(ctx, danglings)
if s.AutoGarbageCollection {
return s.doGarbageCollection(ctx, danglings)
}
return nil
}

func (s *Store) doGarbageCollection(ctx context.Context, danglings []ocispec.Descriptor) error {
Expand Down
Loading

0 comments on commit 5b4e998

Please sign in to comment.