From be1235458d6e1760e0388abdadeb9ea1ce9a2817 Mon Sep 17 00:00:00 2001 From: Malte Poll <1780588+malt3@users.noreply.github.com> Date: Tue, 2 Dec 2025 14:48:07 +0100 Subject: [PATCH] pkg/registry: export ErrNotFound Custom BlobHandler implementations need access to this error. Otherwise it's impossible for them to signal missing blobs. --- pkg/registry/blobs.go | 20 ++++++++++---------- pkg/registry/blobs_disk.go | 5 ++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/registry/blobs.go b/pkg/registry/blobs.go index c83e54799..015a7b310 100644 --- a/pkg/registry/blobs.go +++ b/pkg/registry/blobs.go @@ -103,8 +103,8 @@ func (r *bytesCloser) Close() error { func (e redirectError) Error() string { return fmt.Sprintf("redirecting (%d): %s", e.Code, e.Location) } -// errNotFound represents an error locating the blob. -var errNotFound = errors.New("not found") +// ErrNotFound represents an error locating the blob. +var ErrNotFound = errors.New("not found") type memHandler struct { m map[string][]byte @@ -119,7 +119,7 @@ func (m *memHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error) b, found := m.m[h.String()] if !found { - return 0, errNotFound + return 0, ErrNotFound } return int64(len(b)), nil } @@ -130,7 +130,7 @@ func (m *memHandler) Get(_ context.Context, _ string, h v1.Hash) (io.ReadCloser, b, found := m.m[h.String()] if !found { - return nil, errNotFound + return nil, ErrNotFound } return &bytesCloser{bytes.NewReader(b)}, nil } @@ -153,7 +153,7 @@ func (m *memHandler) Delete(_ context.Context, _ string, h v1.Hash) error { defer m.lock.Unlock() if _, found := m.m[h.String()]; !found { - return errNotFound + return ErrNotFound } delete(m.m, h.String()) @@ -206,7 +206,7 @@ func (b *blobs) handle(resp http.ResponseWriter, req *http.Request) *regError { var size int64 if bsh, ok := b.blobHandler.(BlobStatHandler); ok { size, err = bsh.Stat(req.Context(), repo, h) - if errors.Is(err, errNotFound) { + if errors.Is(err, ErrNotFound) { return regErrBlobUnknown } else if err != nil { var rerr redirectError @@ -218,7 +218,7 @@ func (b *blobs) handle(resp http.ResponseWriter, req *http.Request) *regError { } } else { rc, err := b.blobHandler.Get(req.Context(), repo, h) - if errors.Is(err, errNotFound) { + if errors.Is(err, ErrNotFound) { return regErrBlobUnknown } else if err != nil { var rerr redirectError @@ -254,7 +254,7 @@ func (b *blobs) handle(resp http.ResponseWriter, req *http.Request) *regError { var r io.Reader if bsh, ok := b.blobHandler.(BlobStatHandler); ok { size, err = bsh.Stat(req.Context(), repo, h) - if errors.Is(err, errNotFound) { + if errors.Is(err, ErrNotFound) { return regErrBlobUnknown } else if err != nil { var rerr redirectError @@ -266,7 +266,7 @@ func (b *blobs) handle(resp http.ResponseWriter, req *http.Request) *regError { } rc, err := b.blobHandler.Get(req.Context(), repo, h) - if errors.Is(err, errNotFound) { + if errors.Is(err, ErrNotFound) { return regErrBlobUnknown } else if err != nil { var rerr redirectError @@ -283,7 +283,7 @@ func (b *blobs) handle(resp http.ResponseWriter, req *http.Request) *regError { } else { tmp, err := b.blobHandler.Get(req.Context(), repo, h) - if errors.Is(err, errNotFound) { + if errors.Is(err, ErrNotFound) { return regErrBlobUnknown } else if err != nil { var rerr redirectError diff --git a/pkg/registry/blobs_disk.go b/pkg/registry/blobs_disk.go index 361390f04..b624d22f6 100644 --- a/pkg/registry/blobs_disk.go +++ b/pkg/registry/blobs_disk.go @@ -37,15 +37,17 @@ func (m *diskHandler) blobHashPath(h v1.Hash) string { func (m *diskHandler) Stat(_ context.Context, _ string, h v1.Hash) (int64, error) { fi, err := os.Stat(m.blobHashPath(h)) if errors.Is(err, os.ErrNotExist) { - return 0, errNotFound + return 0, ErrNotFound } else if err != nil { return 0, err } return fi.Size(), nil } + func (m *diskHandler) Get(_ context.Context, _ string, h v1.Hash) (io.ReadCloser, error) { return os.Open(m.blobHashPath(h)) } + 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 // during the os.Rename. The filenames cannot conflict. @@ -66,6 +68,7 @@ func (m *diskHandler) Put(_ context.Context, _ string, h v1.Hash, rc io.ReadClos } return os.Rename(f.Name(), m.blobHashPath(h)) } + func (m *diskHandler) Delete(_ context.Context, _ string, h v1.Hash) error { return os.Remove(m.blobHashPath(h)) }