@@ -53,12 +53,16 @@ type Store struct {
53
53
root string
54
54
indexPath string
55
55
index * ocispec.Index
56
- indexLock sync.Mutex
57
- sync sync.RWMutex
58
-
59
- storage * Storage
60
- tagResolver * resolver.Memory
61
- graph * graph.Memory
56
+ storage * Storage
57
+ tagResolver * resolver.Memory
58
+ graph * graph.Memory
59
+
60
+ // sync ensures that most operations can be done concurrently, while Delete
61
+ // has the exclusive access to Store if a delete operation is underway. Operations
62
+ // such as Fetch, Push use sync.RLock(), while Delete uses sync.Lock().
63
+ sync sync.RWMutex
64
+ // indexLock ensures that only one process is writing to the index.
65
+ indexLock sync.Mutex
62
66
}
63
67
64
68
// New creates a new OCI store with context.Background().
@@ -100,8 +104,8 @@ func NewWithContext(ctx context.Context, root string) (*Store, error) {
100
104
}
101
105
102
106
// Fetch fetches the content identified by the descriptor. It returns an io.ReadCloser.
103
- // It's recommended to close the io.ReadCloser before a DeletableStore. Delete
104
- // operation, otherwise Delete may fail (for example on NTFS file systems).
107
+ // It's recommended to close the io.ReadCloser before a Delete operation, otherwise
108
+ // Delete may fail (for example on NTFS file systems).
105
109
func (s * Store ) Fetch (ctx context.Context , target ocispec.Descriptor ) (io.ReadCloser , error ) {
106
110
s .sync .RLock ()
107
111
defer s .sync .RUnlock ()
@@ -154,7 +158,7 @@ func (s *Store) Delete(ctx context.Context, target ocispec.Descriptor) error {
154
158
return err
155
159
}
156
160
if untagged && s .AutoSaveIndex {
157
- err := s .SaveIndex ()
161
+ err := s .saveIndex ()
158
162
if err != nil {
159
163
return err
160
164
}
@@ -197,7 +201,7 @@ func (s *Store) tag(ctx context.Context, desc ocispec.Descriptor, reference stri
197
201
return err
198
202
}
199
203
if s .AutoSaveIndex {
200
- return s .SaveIndex ()
204
+ return s .saveIndex ()
201
205
}
202
206
return nil
203
207
}
@@ -318,6 +322,13 @@ func (s *Store) loadIndexFile(ctx context.Context) error {
318
322
// - If AutoSaveIndex is set to false, it's the caller's responsibility
319
323
// to manually call this method when needed.
320
324
func (s * Store ) SaveIndex () error {
325
+ s .sync .RLock ()
326
+ defer s .sync .RUnlock ()
327
+
328
+ return s .saveIndex ()
329
+ }
330
+
331
+ func (s * Store ) saveIndex () error {
321
332
s .indexLock .Lock ()
322
333
defer s .indexLock .Unlock ()
323
334
0 commit comments