Skip to content

Commit 5b4e998

Browse files
added the Store field GCEnabled
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
1 parent 2795dd7 commit 5b4e998

File tree

2 files changed

+210
-174
lines changed

2 files changed

+210
-174
lines changed

content/oci/oci.go

+25-13
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ type Store struct {
5252
// to manually call SaveIndex() when needed.
5353
// - Default value: true.
5454
AutoSaveIndex bool
55-
root string
56-
indexPath string
57-
index *ocispec.Index
58-
storage *Storage
59-
tagResolver *resolver.Memory
60-
graph *graph.Memory
55+
56+
// AutoGarbageCollection controls if the OCI store will automatically clean
57+
// dangling nodes during Delete() operation.
58+
// - If AutoGarbageCollection is set to false, it's the user's responsibility
59+
// to manually delete the dangling nodes.
60+
// - Default value: true.
61+
AutoGarbageCollection bool
62+
63+
root string
64+
indexPath string
65+
index *ocispec.Index
66+
storage *Storage
67+
tagResolver *resolver.Memory
68+
graph *graph.Memory
6169

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

8694
store := &Store{
87-
AutoSaveIndex: true,
88-
root: rootAbs,
89-
indexPath: filepath.Join(rootAbs, ocispec.ImageIndexFile),
90-
storage: storage,
91-
tagResolver: resolver.NewMemory(),
92-
graph: graph.NewMemory(),
95+
AutoSaveIndex: true,
96+
AutoGarbageCollection: true,
97+
root: rootAbs,
98+
indexPath: filepath.Join(rootAbs, ocispec.ImageIndexFile),
99+
storage: storage,
100+
tagResolver: resolver.NewMemory(),
101+
graph: graph.NewMemory(),
93102
}
94103

95104
if err := ensureDir(filepath.Join(rootAbs, ocispec.ImageBlobsDir)); err != nil {
@@ -170,7 +179,10 @@ func (s *Store) doDelete(ctx context.Context, target ocispec.Descriptor) error {
170179
if err := s.storage.Delete(ctx, target); err != nil {
171180
return err
172181
}
173-
return s.doGarbageCollection(ctx, danglings)
182+
if s.AutoGarbageCollection {
183+
return s.doGarbageCollection(ctx, danglings)
184+
}
185+
return nil
174186
}
175187

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

0 commit comments

Comments
 (0)