forked from TrueCloudLab/distribution
Merge pull request #3788 from thaJeztah/deprecate_ReadSeekCloser
This commit is contained in:
commit
5357c45703
8 changed files with 48 additions and 49 deletions
14
blobs.go
14
blobs.go
|
@ -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.
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -139,16 +139,14 @@ func NewRepository(name reference.Named, baseURL string, transport http.RoundTri
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{
|
|
||||||
Transport: transport,
|
|
||||||
CheckRedirect: checkHTTPRedirect,
|
|
||||||
// TODO(dmcgowan): create cookie jar
|
|
||||||
}
|
|
||||||
|
|
||||||
return &repository{
|
return &repository{
|
||||||
client: client,
|
client: &http.Client{
|
||||||
ub: ub,
|
Transport: transport,
|
||||||
name: name,
|
CheckRedirect: checkHTTPRedirect,
|
||||||
|
// TODO(dmcgowan): create cookie jar
|
||||||
|
},
|
||||||
|
ub: ub,
|
||||||
|
name: name,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,16 +161,15 @@ func (r *repository) Named() reference.Named {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *repository) Blobs(ctx context.Context) distribution.BlobStore {
|
func (r *repository) Blobs(ctx context.Context) distribution.BlobStore {
|
||||||
statter := &blobStatter{
|
return &blobs{
|
||||||
name: r.name,
|
name: r.name,
|
||||||
ub: r.ub,
|
ub: r.ub,
|
||||||
client: r.client,
|
client: r.client,
|
||||||
}
|
statter: cache.NewCachedBlobStatter(memory.NewInMemoryBlobDescriptorCacheProvider(memory.UnlimitedSize), &blobStatter{
|
||||||
return &blobs{
|
name: r.name,
|
||||||
name: r.name,
|
ub: r.ub,
|
||||||
ub: r.ub,
|
client: r.client,
|
||||||
client: r.client,
|
}),
|
||||||
statter: cache.NewCachedBlobStatter(memory.NewInMemoryBlobDescriptorCacheProvider(memory.UnlimitedSize), statter),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,7 +674,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
|
||||||
|
@ -687,13 +684,12 @@ 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
|
}
|
||||||
}
|
return HandleErrorResponse(resp)
|
||||||
return HandleErrorResponse(resp)
|
}), nil
|
||||||
}), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bs *blobs) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error {
|
func (bs *blobs) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error {
|
||||||
|
|
|
@ -20,17 +20,17 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadSeekCloser combines io.ReadSeeker with io.Closer.
|
// ReadSeekCloser combines io.ReadSeeker with io.Closer.
|
||||||
type ReadSeekCloser interface {
|
//
|
||||||
io.ReadSeeker
|
// Deprecated: use [io.ReadSeekCloser].
|
||||||
io.Closer
|
type ReadSeekCloser = io.ReadSeekCloser
|
||||||
}
|
|
||||||
|
|
||||||
// NewHTTPReadSeeker handles reading from an HTTP endpoint using a GET
|
// NewHTTPReadSeeker handles reading from an HTTP endpoint using a GET
|
||||||
// request. When seeking and starting a read from a non-zero offset
|
// request. When seeking and starting a read from a non-zero offset
|
||||||
// the a "Range" header will be added which sets the offset.
|
// the a "Range" header will be added which sets the offset.
|
||||||
|
//
|
||||||
// TODO(dmcgowan): Move this into a separate utility package
|
// TODO(dmcgowan): Move this into a separate utility package
|
||||||
func NewHTTPReadSeeker(ctx context.Context, client *http.Client, url string, errorHandler func(*http.Response) error) ReadSeekCloser {
|
func NewHTTPReadSeeker(ctx context.Context, client *http.Client, url string, errorHandler func(*http.Response) error) *HTTPReadSeeker {
|
||||||
return &httpReadSeeker{
|
return &HTTPReadSeeker{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
client: client,
|
client: client,
|
||||||
url: url,
|
url: url,
|
||||||
|
@ -38,7 +38,8 @@ func NewHTTPReadSeeker(ctx context.Context, client *http.Client, url string, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpReadSeeker struct {
|
// HTTPReadSeeker implements an [io.ReadSeekCloser].
|
||||||
|
type HTTPReadSeeker struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
client *http.Client
|
client *http.Client
|
||||||
url string
|
url string
|
||||||
|
@ -63,7 +64,7 @@ type httpReadSeeker struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrs *httpReadSeeker) Read(p []byte) (n int, err error) {
|
func (hrs *HTTPReadSeeker) Read(p []byte) (n int, err error) {
|
||||||
if hrs.err != nil {
|
if hrs.err != nil {
|
||||||
return 0, hrs.err
|
return 0, hrs.err
|
||||||
}
|
}
|
||||||
|
@ -92,7 +93,7 @@ func (hrs *httpReadSeeker) Read(p []byte) (n int, err error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrs *httpReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
func (hrs *HTTPReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
||||||
if hrs.err != nil {
|
if hrs.err != nil {
|
||||||
return 0, hrs.err
|
return 0, hrs.err
|
||||||
}
|
}
|
||||||
|
@ -135,7 +136,7 @@ func (hrs *httpReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
||||||
return hrs.seekOffset, err
|
return hrs.seekOffset, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrs *httpReadSeeker) Close() error {
|
func (hrs *HTTPReadSeeker) Close() error {
|
||||||
if hrs.err != nil {
|
if hrs.err != nil {
|
||||||
return hrs.err
|
return hrs.err
|
||||||
}
|
}
|
||||||
|
@ -152,7 +153,7 @@ func (hrs *httpReadSeeker) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrs *httpReadSeeker) reset() {
|
func (hrs *HTTPReadSeeker) reset() {
|
||||||
if hrs.err != nil {
|
if hrs.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -162,7 +163,7 @@ func (hrs *httpReadSeeker) reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hrs *httpReadSeeker) reader() (io.Reader, error) {
|
func (hrs *HTTPReadSeeker) reader() (io.Reader, error) {
|
||||||
if hrs.err != nil {
|
if hrs.err != nil {
|
||||||
return nil, hrs.err
|
return nil, hrs.err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue