Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mimic oci-layout in diskblobhandler #1810

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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))
Dismissed Show dismissed Hide dismissed
if errors.Is(err, os.ErrNotExist) {
return 0, errNotFound
} else if err != nil {
Expand All @@ -40,7 +44,7 @@
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))
Dismissed Show dismissed Hide dismissed
}
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 @@
}(); 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 {
Dismissed Show dismissed Hide dismissed
return err
}
return os.Rename(f.Name(), m.blobHashPath(h))
Dismissed Show dismissed Hide dismissed
}
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))
Dismissed Show dismissed Hide dismissed
}
5 changes: 3 additions & 2 deletions pkg/registry/blobs_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package registry_test

import (
"fmt"
"net/http/httptest"
"os"
"path/filepath"
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestDiskPush(t *testing.T) {
if h, err := img.ConfigName(); err != nil {
t.Fatal(err)
} else {
want[h.String()] = true
want[fmt.Sprintf("%s/%s", h.Algorithm, h.Hex)] = true
}
ls, err := img.Layers()
if err != nil {
Expand All @@ -69,7 +70,7 @@ func TestDiskPush(t *testing.T) {
if h, err := l.Digest(); err != nil {
t.Fatal(err)
} else {
want[h.String()] = true
want[fmt.Sprintf("%s/%s", h.Algorithm, h.Hex)] = true
}
}

Expand Down
Loading