@@ -20,22 +20,17 @@ import (
2020 "io"
2121 "os"
2222 "path/filepath"
23- "sync"
2423
2524 v1 "github.com/google/go-containerregistry/pkg/v1"
2625)
2726
2827type diskHandler struct {
29- dir string
30- lock sync.RWMutex
28+ dir string
3129}
3230
3331func NewDiskBlobHandler (dir string ) BlobHandler { return & diskHandler {dir : dir } }
3432
3533func (m * diskHandler ) Stat (_ context.Context , _ string , h v1.Hash ) (int64 , error ) {
36- m .lock .RLock ()
37- defer m .lock .RUnlock ()
38-
3934 fi , err := os .Stat (filepath .Join (m .dir , h .String ()))
4035 if errors .Is (err , os .ErrNotExist ) {
4136 return 0 , errNotFound
@@ -45,9 +40,6 @@ func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error
4540 return fi .Size (), nil
4641}
4742func (m * diskHandler ) Get (_ context.Context , _ string , h v1.Hash ) (io.ReadCloser , error ) {
48- m .lock .RLock ()
49- defer m .lock .RUnlock ()
50-
5143 return os .Open (filepath .Join (m .dir , h .String ()))
5244}
5345func (m * diskHandler ) Put (_ context.Context , _ string , h v1.Hash , rc io.ReadCloser ) error {
@@ -66,16 +58,8 @@ func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadClos
6658 return err
6759 }
6860
69- // Only lock for the atomic copy of the blob into its final place to avoid
70- // holding the lock excessively long.
71- m .lock .Lock ()
72- defer m .lock .Unlock ()
73-
7461 return os .Rename (f .Name (), filepath .Join (m .dir , h .String ()))
7562}
7663func (m * diskHandler ) Delete (_ context.Context , _ string , h v1.Hash ) error {
77- m .lock .Lock ()
78- defer m .lock .Unlock ()
79-
8064 return os .Remove (filepath .Join (m .dir , h .String ()))
8165}
0 commit comments