@@ -30,8 +30,12 @@ type diskHandler struct {
3030
3131func NewDiskBlobHandler (dir string ) BlobHandler { return & diskHandler {dir : dir } }
3232
33+ func (m * diskHandler ) blobHashPath (h v1.Hash ) string {
34+ return filepath .Join (m .dir , h .Algorithm , h .Hex )
35+ }
36+
3337func (m * diskHandler ) Stat (_ context.Context , _ string , h v1.Hash ) (int64 , error ) {
34- fi , err := os .Stat (filepath . Join ( m . dir , h . String () ))
38+ fi , err := os .Stat (m . blobHashPath ( h ))
3539 if errors .Is (err , os .ErrNotExist ) {
3640 return 0 , errNotFound
3741 } else if err != nil {
@@ -40,7 +44,7 @@ func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error
4044 return fi .Size (), nil
4145}
4246func (m * diskHandler ) Get (_ context.Context , _ string , h v1.Hash ) (io.ReadCloser , error ) {
43- return os .Open (filepath . Join ( m . dir , h . String () ))
47+ return os .Open (m . blobHashPath ( h ))
4448}
4549func (m * diskHandler ) Put (_ context.Context , _ string , h v1.Hash , rc io.ReadCloser ) error {
4650 // Put the temp file in the same directory to avoid cross-device problems
@@ -57,9 +61,11 @@ func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadClos
5761 }(); err != nil {
5862 return err
5963 }
60-
61- return os .Rename (f .Name (), filepath .Join (m .dir , h .String ()))
64+ if err := os .MkdirAll (filepath .Join (m .dir , h .Algorithm ), os .ModePerm ); err != nil {
65+ return err
66+ }
67+ return os .Rename (f .Name (), m .blobHashPath (h ))
6268}
6369func (m * diskHandler ) Delete (_ context.Context , _ string , h v1.Hash ) error {
64- return os .Remove (filepath . Join ( m . dir , h . String () ))
70+ return os .Remove (m . blobHashPath ( h ))
6571}
0 commit comments