deprecate ReadSeekCloser in favor of io.ReadSeekCloser

Go's io package in stdlib now defines this interface, so we can switch
to using that instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-10 17:15:53 +01:00
parent 9d38ed78d2
commit 019ead86f5
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
7 changed files with 22 additions and 21 deletions

View file

@ -142,20 +142,18 @@ type BlobDescriptorServiceFactory interface {
// ReadSeekCloser is the primary reader type for blob data, combining // ReadSeekCloser is the primary reader type for blob data, combining
// io.ReadSeeker with io.Closer. // io.ReadSeeker with io.Closer.
type ReadSeekCloser interface { //
io.ReadSeeker // Deprecated: use [io.ReadSeekCloser].
io.Closer type ReadSeekCloser = io.ReadSeekCloser
}
// BlobProvider describes operations for getting blob data. // BlobProvider describes operations for getting blob data.
type BlobProvider interface { type BlobProvider interface {
// Get returns the entire blob identified by digest along with the descriptor. // Get returns the entire blob identified by digest along with the descriptor.
Get(ctx context.Context, dgst digest.Digest) ([]byte, error) Get(ctx context.Context, dgst digest.Digest) ([]byte, error)
// Open provides a ReadSeekCloser to the blob identified by the provided // Open provides an [io.ReadSeekCloser] to the blob identified by the provided
// descriptor. If the blob is not known to the service, an error will be // descriptor. If the blob is not known to the service, an error is returned.
// returned. Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error)
Open(ctx context.Context, dgst digest.Digest) (ReadSeekCloser, error)
} }
// BlobServer can serve blobs via http. // BlobServer can serve blobs via http.

View file

@ -2,6 +2,7 @@ package notifications
import ( import (
"context" "context"
"io"
"net/http" "net/http"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
@ -147,7 +148,7 @@ func (bsl *blobServiceListener) Get(ctx context.Context, dgst digest.Digest) ([]
return p, err return p, err
} }
func (bsl *blobServiceListener) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (bsl *blobServiceListener) Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error) {
rc, err := bsl.BlobStore.Open(ctx, dgst) rc, err := bsl.BlobStore.Open(ctx, dgst)
if err == nil { if err == nil {
if desc, err := bsl.Stat(ctx, dgst); err != nil { if desc, err := bsl.Stat(ctx, dgst); err != nil {

View file

@ -676,7 +676,7 @@ func (bs *blobs) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) {
return io.ReadAll(reader) return io.ReadAll(reader)
} }
func (bs *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (bs *blobs) Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error) {
ref, err := reference.WithDigest(bs.name, dgst) ref, err := reference.WithDigest(bs.name, dgst)
if err != nil { if err != nil {
return nil, err return nil, err
@ -686,8 +686,7 @@ func (bs *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.Rea
return nil, err return nil, err
} }
return transport.NewHTTPReadSeeker(ctx, bs.client, blobURL, return transport.NewHTTPReadSeeker(ctx, bs.client, blobURL, func(resp *http.Response) error {
func(resp *http.Response) error {
if resp.StatusCode == http.StatusNotFound { if resp.StatusCode == http.StatusNotFound {
return distribution.ErrBlobUnknown return distribution.ErrBlobUnknown
} }

View file

@ -213,7 +213,7 @@ func (pbs *proxyBlobStore) Mount(ctx context.Context, sourceRepo reference.Named
return distribution.Descriptor{}, distribution.ErrUnsupported return distribution.Descriptor{}, distribution.ErrUnsupported
} }
func (pbs *proxyBlobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (pbs *proxyBlobStore) Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error) {
return nil, distribution.ErrUnsupported return nil, distribution.ErrUnsupported
} }

View file

@ -2,6 +2,7 @@ package proxy
import ( import (
"context" "context"
"io"
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -58,7 +59,7 @@ func (sbs statsBlobStore) Resume(ctx context.Context, id string) (distribution.B
return sbs.blobs.Resume(ctx, id) return sbs.blobs.Resume(ctx, id)
} }
func (sbs statsBlobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (sbs statsBlobStore) Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error) {
sbsMu.Lock() sbsMu.Lock()
sbs.stats["open"]++ sbs.stats["open"]++
sbsMu.Unlock() sbsMu.Unlock()

View file

@ -2,6 +2,7 @@ package storage
import ( import (
"context" "context"
"io"
"path" "path"
"github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3"
@ -41,7 +42,7 @@ func (bs *blobStore) Get(ctx context.Context, dgst digest.Digest) ([]byte, error
return p, nil return p, nil
} }
func (bs *blobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (bs *blobStore) Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error) {
desc, err := bs.statter.Stat(ctx, dgst) desc, err := bs.statter.Stat(ctx, dgst)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -3,6 +3,7 @@ package storage
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"net/http" "net/http"
"path" "path"
"time" "time"
@ -57,7 +58,7 @@ func (lbs *linkedBlobStore) Get(ctx context.Context, dgst digest.Digest) ([]byte
return lbs.blobStore.Get(ctx, canonical.Digest) return lbs.blobStore.Get(ctx, canonical.Digest)
} }
func (lbs *linkedBlobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { func (lbs *linkedBlobStore) Open(ctx context.Context, dgst digest.Digest) (io.ReadSeekCloser, error) {
canonical, err := lbs.Stat(ctx, dgst) // access check canonical, err := lbs.Stat(ctx, dgst) // access check
if err != nil { if err != nil {
return nil, err return nil, err