@@ -52,12 +52,20 @@ type Store struct {
52
52
// to manually call SaveIndex() when needed.
53
53
// - Default value: true.
54
54
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
61
69
62
70
// sync ensures that most operations can be done concurrently, while Delete
63
71
// 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) {
84
92
}
85
93
86
94
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 (),
93
102
}
94
103
95
104
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 {
170
179
if err := s .storage .Delete (ctx , target ); err != nil {
171
180
return err
172
181
}
173
- return s .doGarbageCollection (ctx , danglings )
182
+ if s .AutoGarbageCollection {
183
+ return s .doGarbageCollection (ctx , danglings )
184
+ }
185
+ return nil
174
186
}
175
187
176
188
func (s * Store ) doGarbageCollection (ctx context.Context , danglings []ocispec.Descriptor ) error {
0 commit comments