Skip to content

Commit

Permalink
fix: mimic oci-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Oct 11, 2023
1 parent dbcd01c commit 9595027
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/registry/blobs_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ type diskHandler struct {

func NewDiskBlobHandler(dir string) BlobHandler { return &diskHandler{dir: dir} }

func (m *diskHandler) blobHashPath(h v1.Hash) string {
return filepath.Join(m.dir, h.Algorithm, h.Hex)
}

func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error) {
fi, err := os.Stat(filepath.Join(m.dir, h.String()))
fi, err := os.Stat(m.blobHashPath(h))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
if errors.Is(err, os.ErrNotExist) {
return 0, errNotFound
} else if err != nil {
Expand All @@ -40,7 +44,7 @@ func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error
return fi.Size(), nil
}
func (m *diskHandler) Get(_ context.Context, _ string, h v1.Hash) (io.ReadCloser, error) {
return os.Open(filepath.Join(m.dir, h.String()))
return os.Open(m.blobHashPath(h))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
}
func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadCloser) error {
// Put the temp file in the same directory to avoid cross-device problems
Expand All @@ -57,9 +61,11 @@ func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadClos
}(); err != nil {
return err
}

return os.Rename(f.Name(), filepath.Join(m.dir, h.String()))
if err := os.MkdirAll(filepath.Join(m.dir, h.Algorithm), os.ModePerm); err != nil {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
return err
}
return os.Rename(f.Name(), m.blobHashPath(h))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
}
func (m *diskHandler) Delete(_ context.Context, _ string, h v1.Hash) error {
return os.Remove(filepath.Join(m.dir, h.String()))
return os.Remove(m.blobHashPath(h))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
}

0 comments on commit 9595027

Please sign in to comment.