Skip to content
Open
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
20 changes: 10 additions & 10 deletions pkg/registry/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/registry/blobs_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
}