Merge pull request #410 from RichardScothern/driver-context
Add golang/x/net/context.Context to storage driver method calls
This commit is contained in:
commit
3a0d6faba1
30 changed files with 383 additions and 343 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"github.com/docker/distribution/registry/storage/driver/base"
|
||||
"github.com/docker/distribution/registry/storage/driver/factory"
|
||||
|
@ -99,7 +100,7 @@ func (d *driver) Name() string {
|
|||
}
|
||||
|
||||
// GetContent retrieves the content stored at "path" as a []byte.
|
||||
func (d *driver) GetContent(path string) ([]byte, error) {
|
||||
func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
|
||||
blob, err := d.client.GetBlob(d.container, path)
|
||||
if err != nil {
|
||||
if is404(err) {
|
||||
|
@ -112,13 +113,13 @@ func (d *driver) GetContent(path string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// PutContent stores the []byte content at a location designated by "path".
|
||||
func (d *driver) PutContent(path string, contents []byte) error {
|
||||
func (d *driver) PutContent(ctx context.Context, path string, contents []byte) error {
|
||||
return d.client.PutBlockBlob(d.container, path, ioutil.NopCloser(bytes.NewReader(contents)))
|
||||
}
|
||||
|
||||
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a
|
||||
// given byte offset.
|
||||
func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
||||
func (d *driver) ReadStream(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
||||
if ok, err := d.client.BlobExists(d.container, path); err != nil {
|
||||
return nil, err
|
||||
} else if !ok {
|
||||
|
@ -145,7 +146,7 @@ func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
|||
|
||||
// WriteStream stores the contents of the provided io.ReadCloser at a location
|
||||
// designated by the given path.
|
||||
func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (int64, error) {
|
||||
func (d *driver) WriteStream(ctx context.Context, path string, offset int64, reader io.Reader) (int64, error) {
|
||||
if blobExists, err := d.client.BlobExists(d.container, path); err != nil {
|
||||
return 0, err
|
||||
} else if !blobExists {
|
||||
|
@ -166,7 +167,7 @@ func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (int64
|
|||
|
||||
// Stat retrieves the FileInfo for the given path, including the current size
|
||||
// in bytes and the creation time.
|
||||
func (d *driver) Stat(path string) (storagedriver.FileInfo, error) {
|
||||
func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) {
|
||||
// Check if the path is a blob
|
||||
if ok, err := d.client.BlobExists(d.container, path); err != nil {
|
||||
return nil, err
|
||||
|
@ -215,7 +216,7 @@ func (d *driver) Stat(path string) (storagedriver.FileInfo, error) {
|
|||
|
||||
// List returns a list of the objects that are direct descendants of the given
|
||||
// path.
|
||||
func (d *driver) List(path string) ([]string, error) {
|
||||
func (d *driver) List(ctx context.Context, path string) ([]string, error) {
|
||||
if path == "/" {
|
||||
path = ""
|
||||
}
|
||||
|
@ -231,7 +232,7 @@ func (d *driver) List(path string) ([]string, error) {
|
|||
|
||||
// Move moves an object stored at sourcePath to destPath, removing the original
|
||||
// object.
|
||||
func (d *driver) Move(sourcePath string, destPath string) error {
|
||||
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
|
||||
sourceBlobURL := d.client.GetBlobUrl(d.container, sourcePath)
|
||||
err := d.client.CopyBlob(d.container, destPath, sourceBlobURL)
|
||||
if err != nil {
|
||||
|
@ -245,7 +246,7 @@ func (d *driver) Move(sourcePath string, destPath string) error {
|
|||
}
|
||||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
func (d *driver) Delete(path string) error {
|
||||
func (d *driver) Delete(ctx context.Context, path string) error {
|
||||
ok, err := d.client.DeleteBlobIfExists(d.container, path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -275,7 +276,7 @@ func (d *driver) Delete(path string) error {
|
|||
// URLFor returns a publicly accessible URL for the blob stored at given path
|
||||
// for specified duration by making use of Azure Storage Shared Access Signatures (SAS).
|
||||
// See https://msdn.microsoft.com/en-us/library/azure/ee395415.aspx for more info.
|
||||
func (d *driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
expiresTime := time.Now().UTC().Add(20 * time.Minute) // default expiration
|
||||
expires, ok := options["expiry"]
|
||||
if ok {
|
||||
|
|
|
@ -51,32 +51,32 @@ type Base struct {
|
|||
}
|
||||
|
||||
// GetContent wraps GetContent of underlying storage driver.
|
||||
func (base *Base) GetContent(path string) ([]byte, error) {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) GetContent(ctx context.Context, path string) ([]byte, error) {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.GetContent(%q)", base.Name(), path)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(path) {
|
||||
return nil, storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.GetContent(path)
|
||||
return base.StorageDriver.GetContent(ctx, path)
|
||||
}
|
||||
|
||||
// PutContent wraps PutContent of underlying storage driver.
|
||||
func (base *Base) PutContent(path string, content []byte) error {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) PutContent(ctx context.Context, path string, content []byte) error {
|
||||
ctx, done := context.WithTrace(context.Background())
|
||||
defer done("%s.PutContent(%q)", base.Name(), path)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(path) {
|
||||
return storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.PutContent(path, content)
|
||||
return base.StorageDriver.PutContent(ctx, path, content)
|
||||
}
|
||||
|
||||
// ReadStream wraps ReadStream of underlying storage driver.
|
||||
func (base *Base) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) ReadStream(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
||||
ctx, done := context.WithTrace(context.Background())
|
||||
defer done("%s.ReadStream(%q, %d)", base.Name(), path, offset)
|
||||
|
||||
if offset < 0 {
|
||||
|
@ -87,12 +87,12 @@ func (base *Base) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
|||
return nil, storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.ReadStream(path, offset)
|
||||
return base.StorageDriver.ReadStream(ctx, path, offset)
|
||||
}
|
||||
|
||||
// WriteStream wraps WriteStream of underlying storage driver.
|
||||
func (base *Base) WriteStream(path string, offset int64, reader io.Reader) (nn int64, err error) {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) WriteStream(ctx context.Context, path string, offset int64, reader io.Reader) (nn int64, err error) {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.WriteStream(%q, %d)", base.Name(), path, offset)
|
||||
|
||||
if offset < 0 {
|
||||
|
@ -103,36 +103,36 @@ func (base *Base) WriteStream(path string, offset int64, reader io.Reader) (nn i
|
|||
return 0, storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.WriteStream(path, offset, reader)
|
||||
return base.StorageDriver.WriteStream(ctx, path, offset, reader)
|
||||
}
|
||||
|
||||
// Stat wraps Stat of underlying storage driver.
|
||||
func (base *Base) Stat(path string) (storagedriver.FileInfo, error) {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.Stat(%q)", base.Name(), path)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(path) {
|
||||
return nil, storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.Stat(path)
|
||||
return base.StorageDriver.Stat(ctx, path)
|
||||
}
|
||||
|
||||
// List wraps List of underlying storage driver.
|
||||
func (base *Base) List(path string) ([]string, error) {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) List(ctx context.Context, path string) ([]string, error) {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.List(%q)", base.Name(), path)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(path) && path != "/" {
|
||||
return nil, storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.List(path)
|
||||
return base.StorageDriver.List(ctx, path)
|
||||
}
|
||||
|
||||
// Move wraps Move of underlying storage driver.
|
||||
func (base *Base) Move(sourcePath string, destPath string) error {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) Move(ctx context.Context, sourcePath string, destPath string) error {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.Move(%q, %q", base.Name(), sourcePath, destPath)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(sourcePath) {
|
||||
|
@ -141,29 +141,29 @@ func (base *Base) Move(sourcePath string, destPath string) error {
|
|||
return storagedriver.InvalidPathError{Path: destPath}
|
||||
}
|
||||
|
||||
return base.StorageDriver.Move(sourcePath, destPath)
|
||||
return base.StorageDriver.Move(ctx, sourcePath, destPath)
|
||||
}
|
||||
|
||||
// Delete wraps Delete of underlying storage driver.
|
||||
func (base *Base) Delete(path string) error {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) Delete(ctx context.Context, path string) error {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.Delete(%q)", base.Name(), path)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(path) {
|
||||
return storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.Delete(path)
|
||||
return base.StorageDriver.Delete(ctx, path)
|
||||
}
|
||||
|
||||
// URLFor wraps URLFor of underlying storage driver.
|
||||
func (base *Base) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
_, done := context.WithTrace(context.Background())
|
||||
func (base *Base) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
ctx, done := context.WithTrace(ctx)
|
||||
defer done("%s.URLFor(%q)", base.Name(), path)
|
||||
|
||||
if !storagedriver.PathRegexp.MatchString(path) {
|
||||
return "", storagedriver.InvalidPathError{Path: path}
|
||||
}
|
||||
|
||||
return base.StorageDriver.URLFor(path, options)
|
||||
return base.StorageDriver.URLFor(ctx, path, options)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"github.com/docker/distribution/registry/storage/driver/base"
|
||||
"github.com/docker/distribution/registry/storage/driver/factory"
|
||||
|
@ -76,8 +77,8 @@ func (d *driver) Name() string {
|
|||
}
|
||||
|
||||
// GetContent retrieves the content stored at "path" as a []byte.
|
||||
func (d *driver) GetContent(path string) ([]byte, error) {
|
||||
rc, err := d.ReadStream(path, 0)
|
||||
func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
|
||||
rc, err := d.ReadStream(ctx, path, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -92,8 +93,8 @@ func (d *driver) GetContent(path string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// PutContent stores the []byte content at a location designated by "path".
|
||||
func (d *driver) PutContent(subPath string, contents []byte) error {
|
||||
if _, err := d.WriteStream(subPath, 0, bytes.NewReader(contents)); err != nil {
|
||||
func (d *driver) PutContent(ctx context.Context, subPath string, contents []byte) error {
|
||||
if _, err := d.WriteStream(ctx, subPath, 0, bytes.NewReader(contents)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ func (d *driver) PutContent(subPath string, contents []byte) error {
|
|||
|
||||
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a
|
||||
// given byte offset.
|
||||
func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
||||
func (d *driver) ReadStream(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
||||
file, err := os.OpenFile(d.fullPath(path), os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
@ -126,7 +127,7 @@ func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
|||
|
||||
// WriteStream stores the contents of the provided io.Reader at a location
|
||||
// designated by the given path.
|
||||
func (d *driver) WriteStream(subPath string, offset int64, reader io.Reader) (nn int64, err error) {
|
||||
func (d *driver) WriteStream(ctx context.Context, subPath string, offset int64, reader io.Reader) (nn int64, err error) {
|
||||
// TODO(stevvooe): This needs to be a requirement.
|
||||
// if !path.IsAbs(subPath) {
|
||||
// return fmt.Errorf("absolute path required: %q", subPath)
|
||||
|
@ -162,7 +163,7 @@ func (d *driver) WriteStream(subPath string, offset int64, reader io.Reader) (nn
|
|||
|
||||
// Stat retrieves the FileInfo for the given path, including the current size
|
||||
// in bytes and the creation time.
|
||||
func (d *driver) Stat(subPath string) (storagedriver.FileInfo, error) {
|
||||
func (d *driver) Stat(ctx context.Context, subPath string) (storagedriver.FileInfo, error) {
|
||||
fullPath := d.fullPath(subPath)
|
||||
|
||||
fi, err := os.Stat(fullPath)
|
||||
|
@ -182,7 +183,7 @@ func (d *driver) Stat(subPath string) (storagedriver.FileInfo, error) {
|
|||
|
||||
// List returns a list of the objects that are direct descendants of the given
|
||||
// path.
|
||||
func (d *driver) List(subPath string) ([]string, error) {
|
||||
func (d *driver) List(ctx context.Context, subPath string) ([]string, error) {
|
||||
if subPath[len(subPath)-1] != '/' {
|
||||
subPath += "/"
|
||||
}
|
||||
|
@ -213,7 +214,7 @@ func (d *driver) List(subPath string) ([]string, error) {
|
|||
|
||||
// Move moves an object stored at sourcePath to destPath, removing the original
|
||||
// object.
|
||||
func (d *driver) Move(sourcePath string, destPath string) error {
|
||||
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
|
||||
source := d.fullPath(sourcePath)
|
||||
dest := d.fullPath(destPath)
|
||||
|
||||
|
@ -230,7 +231,7 @@ func (d *driver) Move(sourcePath string, destPath string) error {
|
|||
}
|
||||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
func (d *driver) Delete(subPath string) error {
|
||||
func (d *driver) Delete(ctx context.Context, subPath string) error {
|
||||
fullPath := d.fullPath(subPath)
|
||||
|
||||
_, err := os.Stat(fullPath)
|
||||
|
@ -246,7 +247,7 @@ func (d *driver) Delete(subPath string) error {
|
|||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
return "", storagedriver.ErrUnsupportedMethod
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"github.com/docker/distribution/registry/storage/driver/base"
|
||||
"github.com/docker/distribution/registry/storage/driver/factory"
|
||||
|
@ -69,11 +70,11 @@ func (d *driver) Name() string {
|
|||
}
|
||||
|
||||
// GetContent retrieves the content stored at "path" as a []byte.
|
||||
func (d *driver) GetContent(path string) ([]byte, error) {
|
||||
func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
|
||||
d.mutex.RLock()
|
||||
defer d.mutex.RUnlock()
|
||||
|
||||
rc, err := d.ReadStream(path, 0)
|
||||
rc, err := d.ReadStream(ctx, path, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ func (d *driver) GetContent(path string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// PutContent stores the []byte content at a location designated by "path".
|
||||
func (d *driver) PutContent(p string, contents []byte) error {
|
||||
func (d *driver) PutContent(ctx context.Context, p string, contents []byte) error {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
|
@ -102,7 +103,7 @@ func (d *driver) PutContent(p string, contents []byte) error {
|
|||
|
||||
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a
|
||||
// given byte offset.
|
||||
func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
||||
func (d *driver) ReadStream(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
||||
d.mutex.RLock()
|
||||
defer d.mutex.RUnlock()
|
||||
|
||||
|
@ -126,7 +127,7 @@ func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
|||
|
||||
// WriteStream stores the contents of the provided io.ReadCloser at a location
|
||||
// designated by the given path.
|
||||
func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (nn int64, err error) {
|
||||
func (d *driver) WriteStream(ctx context.Context, path string, offset int64, reader io.Reader) (nn int64, err error) {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
|
@ -167,7 +168,7 @@ func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (nn in
|
|||
}
|
||||
|
||||
// Stat returns info about the provided path.
|
||||
func (d *driver) Stat(path string) (storagedriver.FileInfo, error) {
|
||||
func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) {
|
||||
d.mutex.RLock()
|
||||
defer d.mutex.RUnlock()
|
||||
|
||||
|
@ -193,7 +194,7 @@ func (d *driver) Stat(path string) (storagedriver.FileInfo, error) {
|
|||
|
||||
// List returns a list of the objects that are direct descendants of the given
|
||||
// path.
|
||||
func (d *driver) List(path string) ([]string, error) {
|
||||
func (d *driver) List(ctx context.Context, path string) ([]string, error) {
|
||||
d.mutex.RLock()
|
||||
defer d.mutex.RUnlock()
|
||||
|
||||
|
@ -223,7 +224,7 @@ func (d *driver) List(path string) ([]string, error) {
|
|||
|
||||
// Move moves an object stored at sourcePath to destPath, removing the original
|
||||
// object.
|
||||
func (d *driver) Move(sourcePath string, destPath string) error {
|
||||
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
|
@ -239,7 +240,7 @@ func (d *driver) Move(sourcePath string, destPath string) error {
|
|||
}
|
||||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
func (d *driver) Delete(path string) error {
|
||||
func (d *driver) Delete(ctx context.Context, path string) error {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
|
||||
|
@ -256,6 +257,6 @@ func (d *driver) Delete(path string) error {
|
|||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
return "", storagedriver.ErrUnsupportedMethod
|
||||
}
|
||||
|
|
|
@ -98,12 +98,12 @@ type S3BucketKeyer interface {
|
|||
|
||||
// Resolve returns an http.Handler which can serve the contents of the given
|
||||
// Layer, or an error if not supported by the storagedriver.
|
||||
func (lh *cloudFrontStorageMiddleware) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
func (lh *cloudFrontStorageMiddleware) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
// TODO(endophage): currently only supports S3
|
||||
keyer, ok := lh.StorageDriver.(S3BucketKeyer)
|
||||
if !ok {
|
||||
context.GetLogger(context.Background()).Warn("the CloudFront middleware does not support this backend storage driver")
|
||||
return lh.StorageDriver.URLFor(path, options)
|
||||
context.GetLogger(ctx).Warn("the CloudFront middleware does not support this backend storage driver")
|
||||
return lh.StorageDriver.URLFor(ctx, path, options)
|
||||
}
|
||||
|
||||
cfURL, err := lh.cloudfront.CannedSignedURL(keyer.S3BucketKey(path), "", time.Now().Add(lh.duration))
|
||||
|
|
|
@ -29,6 +29,8 @@ import (
|
|||
"github.com/AdRoll/goamz/aws"
|
||||
"github.com/AdRoll/goamz/s3"
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"github.com/docker/distribution/registry/storage/driver/base"
|
||||
"github.com/docker/distribution/registry/storage/driver/factory"
|
||||
|
@ -267,7 +269,7 @@ func (d *driver) Name() string {
|
|||
}
|
||||
|
||||
// GetContent retrieves the content stored at "path" as a []byte.
|
||||
func (d *driver) GetContent(path string) ([]byte, error) {
|
||||
func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
|
||||
content, err := d.Bucket.Get(d.s3Path(path))
|
||||
if err != nil {
|
||||
return nil, parseError(path, err)
|
||||
|
@ -276,13 +278,13 @@ func (d *driver) GetContent(path string) ([]byte, error) {
|
|||
}
|
||||
|
||||
// PutContent stores the []byte content at a location designated by "path".
|
||||
func (d *driver) PutContent(path string, contents []byte) error {
|
||||
func (d *driver) PutContent(ctx context.Context, path string, contents []byte) error {
|
||||
return parseError(path, d.Bucket.Put(d.s3Path(path), contents, d.getContentType(), getPermissions(), d.getOptions()))
|
||||
}
|
||||
|
||||
// ReadStream retrieves an io.ReadCloser for the content stored at "path" with a
|
||||
// given byte offset.
|
||||
func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
||||
func (d *driver) ReadStream(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
|
||||
headers := make(http.Header)
|
||||
headers.Add("Range", "bytes="+strconv.FormatInt(offset, 10)+"-")
|
||||
|
||||
|
@ -304,7 +306,7 @@ func (d *driver) ReadStream(path string, offset int64) (io.ReadCloser, error) {
|
|||
// returned. May be used to resume writing a stream by providing a nonzero
|
||||
// offset. Offsets past the current size will write from the position
|
||||
// beyond the end of the file.
|
||||
func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (totalRead int64, err error) {
|
||||
func (d *driver) WriteStream(ctx context.Context, path string, offset int64, reader io.Reader) (totalRead int64, err error) {
|
||||
partNumber := 1
|
||||
bytesRead := 0
|
||||
var putErrChan chan error
|
||||
|
@ -350,7 +352,7 @@ func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (total
|
|||
|
||||
// Fills from 0 to total from current
|
||||
fromSmallCurrent := func(total int64) error {
|
||||
current, err := d.ReadStream(path, 0)
|
||||
current, err := d.ReadStream(ctx, path, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -638,7 +640,7 @@ func (d *driver) WriteStream(path string, offset int64, reader io.Reader) (total
|
|||
|
||||
// Stat retrieves the FileInfo for the given path, including the current size
|
||||
// in bytes and the creation time.
|
||||
func (d *driver) Stat(path string) (storagedriver.FileInfo, error) {
|
||||
func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, error) {
|
||||
listResponse, err := d.Bucket.List(d.s3Path(path), "", "", 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -671,7 +673,7 @@ func (d *driver) Stat(path string) (storagedriver.FileInfo, error) {
|
|||
}
|
||||
|
||||
// List returns a list of the objects that are direct descendants of the given path.
|
||||
func (d *driver) List(path string) ([]string, error) {
|
||||
func (d *driver) List(ctx context.Context, path string) ([]string, error) {
|
||||
if path != "/" && path[len(path)-1] != '/' {
|
||||
path = path + "/"
|
||||
}
|
||||
|
@ -716,7 +718,7 @@ func (d *driver) List(path string) ([]string, error) {
|
|||
|
||||
// Move moves an object stored at sourcePath to destPath, removing the original
|
||||
// object.
|
||||
func (d *driver) Move(sourcePath string, destPath string) error {
|
||||
func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) error {
|
||||
/* This is terrible, but aws doesn't have an actual move. */
|
||||
_, err := d.Bucket.PutCopy(d.s3Path(destPath), getPermissions(),
|
||||
s3.CopyOptions{Options: d.getOptions(), ContentType: d.getContentType()}, d.Bucket.Name+"/"+d.s3Path(sourcePath))
|
||||
|
@ -724,11 +726,11 @@ func (d *driver) Move(sourcePath string, destPath string) error {
|
|||
return parseError(sourcePath, err)
|
||||
}
|
||||
|
||||
return d.Delete(sourcePath)
|
||||
return d.Delete(ctx, sourcePath)
|
||||
}
|
||||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
func (d *driver) Delete(path string) error {
|
||||
func (d *driver) Delete(ctx context.Context, path string) error {
|
||||
listResponse, err := d.Bucket.List(d.s3Path(path), "", "", listMax)
|
||||
if err != nil || len(listResponse.Contents) == 0 {
|
||||
return storagedriver.PathNotFoundError{Path: path}
|
||||
|
@ -757,7 +759,7 @@ func (d *driver) Delete(path string) error {
|
|||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *driver) URLFor(path string, options map[string]interface{}) (string, error) {
|
||||
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
methodString := "GET"
|
||||
method, ok := options["method"]
|
||||
if ok {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/AdRoll/goamz/aws"
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"github.com/docker/distribution/registry/storage/driver/testsuites"
|
||||
|
||||
|
@ -134,16 +135,17 @@ func (suite *S3DriverSuite) TestEmptyRootList(c *check.C) {
|
|||
|
||||
filename := "/test"
|
||||
contents := []byte("contents")
|
||||
err = rootedDriver.PutContent(filename, contents)
|
||||
ctx := context.Background()
|
||||
err = rootedDriver.PutContent(ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer rootedDriver.Delete(filename)
|
||||
defer rootedDriver.Delete(ctx, filename)
|
||||
|
||||
keys, err := emptyRootDriver.List("/")
|
||||
keys, err := emptyRootDriver.List(ctx, "/")
|
||||
for _, path := range keys {
|
||||
c.Assert(storagedriver.PathRegexp.MatchString(path), check.Equals, true)
|
||||
}
|
||||
|
||||
keys, err = slashRootDriver.List("/")
|
||||
keys, err = slashRootDriver.List(ctx, "/")
|
||||
for _, path := range keys {
|
||||
c.Assert(storagedriver.PathRegexp.MatchString(path), check.Equals, true)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
)
|
||||
|
||||
// Version is a string representing the storage driver version, of the form
|
||||
|
@ -42,45 +44,45 @@ type StorageDriver interface {
|
|||
|
||||
// GetContent retrieves the content stored at "path" as a []byte.
|
||||
// This should primarily be used for small objects.
|
||||
GetContent(path string) ([]byte, error)
|
||||
GetContent(ctx context.Context, path string) ([]byte, error)
|
||||
|
||||
// PutContent stores the []byte content at a location designated by "path".
|
||||
// This should primarily be used for small objects.
|
||||
PutContent(path string, content []byte) error
|
||||
PutContent(ctx context.Context, path string, content []byte) error
|
||||
|
||||
// ReadStream retrieves an io.ReadCloser for the content stored at "path"
|
||||
// with a given byte offset.
|
||||
// May be used to resume reading a stream by providing a nonzero offset.
|
||||
ReadStream(path string, offset int64) (io.ReadCloser, error)
|
||||
ReadStream(ctx context.Context, path string, offset int64) (io.ReadCloser, error)
|
||||
|
||||
// WriteStream stores the contents of the provided io.ReadCloser at a
|
||||
// location designated by the given path.
|
||||
// May be used to resume writing a stream by providing a nonzero offset.
|
||||
// The offset must be no larger than the CurrentSize for this path.
|
||||
WriteStream(path string, offset int64, reader io.Reader) (nn int64, err error)
|
||||
WriteStream(ctx context.Context, path string, offset int64, reader io.Reader) (nn int64, err error)
|
||||
|
||||
// Stat retrieves the FileInfo for the given path, including the current
|
||||
// size in bytes and the creation time.
|
||||
Stat(path string) (FileInfo, error)
|
||||
Stat(ctx context.Context, path string) (FileInfo, error)
|
||||
|
||||
// List returns a list of the objects that are direct descendants of the
|
||||
//given path.
|
||||
List(path string) ([]string, error)
|
||||
List(ctx context.Context, path string) ([]string, error)
|
||||
|
||||
// Move moves an object stored at sourcePath to destPath, removing the
|
||||
// original object.
|
||||
// Note: This may be no more efficient than a copy followed by a delete for
|
||||
// many implementations.
|
||||
Move(sourcePath string, destPath string) error
|
||||
Move(ctx context.Context, sourcePath string, destPath string) error
|
||||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
Delete(path string) error
|
||||
Delete(ctx context.Context, path string) error
|
||||
|
||||
// URLFor returns a URL which may be used to retrieve the content stored at
|
||||
// the given path, possibly using the given options.
|
||||
// May return an ErrUnsupportedMethod in certain StorageDriver
|
||||
// implementations.
|
||||
URLFor(path string, options map[string]interface{}) (string, error)
|
||||
URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
// PathRegexp is the regular expression which each file path must match. A
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"gopkg.in/check.v1"
|
||||
)
|
||||
|
@ -27,6 +28,7 @@ func RegisterInProcessSuite(driverConstructor DriverConstructor, skipCheck SkipC
|
|||
check.Suite(&DriverSuite{
|
||||
Constructor: driverConstructor,
|
||||
SkipCheck: skipCheck,
|
||||
ctx: context.Background(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -88,6 +90,7 @@ type DriverSuite struct {
|
|||
Teardown DriverTeardown
|
||||
SkipCheck
|
||||
storagedriver.StorageDriver
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// SetUpSuite sets up the gocheck test suite.
|
||||
|
@ -112,7 +115,7 @@ func (suite *DriverSuite) TearDownSuite(c *check.C) {
|
|||
// This causes the suite to abort if any files are left around in the storage
|
||||
// driver.
|
||||
func (suite *DriverSuite) TearDownTest(c *check.C) {
|
||||
files, _ := suite.StorageDriver.List("/")
|
||||
files, _ := suite.StorageDriver.List(suite.ctx, "/")
|
||||
if len(files) > 0 {
|
||||
c.Fatalf("Storage driver did not clean up properly. Offending files: %#v", files)
|
||||
}
|
||||
|
@ -141,11 +144,11 @@ func (suite *DriverSuite) TestValidPaths(c *check.C) {
|
|||
"/Abc/Cba"}
|
||||
|
||||
for _, filename := range validFiles {
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
received, err := suite.StorageDriver.GetContent(filename)
|
||||
received, err := suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(received, check.DeepEquals, contents)
|
||||
}
|
||||
|
@ -164,12 +167,12 @@ func (suite *DriverSuite) TestInvalidPaths(c *check.C) {
|
|||
"/abc_123/"}
|
||||
|
||||
for _, filename := range invalidFiles {
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.InvalidPathError{})
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(filename)
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.InvalidPathError{})
|
||||
}
|
||||
|
@ -225,7 +228,7 @@ func (suite *DriverSuite) TestTruncate(c *check.C) {
|
|||
// TestReadNonexistent tests reading content from an empty path.
|
||||
func (suite *DriverSuite) TestReadNonexistent(c *check.C) {
|
||||
filename := randomPath(32)
|
||||
_, err := suite.StorageDriver.GetContent(filename)
|
||||
_, err := suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -277,17 +280,17 @@ func (suite *DriverSuite) TestWriteReadLargeStreams(c *check.C) {
|
|||
}
|
||||
|
||||
filename := randomPath(32)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
checksum := sha1.New()
|
||||
var fileSize int64 = 5 * 1024 * 1024 * 1024
|
||||
|
||||
contents := newRandReader(fileSize)
|
||||
written, err := suite.StorageDriver.WriteStream(filename, 0, io.TeeReader(contents, checksum))
|
||||
written, err := suite.StorageDriver.WriteStream(suite.ctx, filename, 0, io.TeeReader(contents, checksum))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(written, check.Equals, fileSize)
|
||||
|
||||
reader, err := suite.StorageDriver.ReadStream(filename, 0)
|
||||
reader, err := suite.StorageDriver.ReadStream(suite.ctx, filename, 0)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
writtenChecksum := sha1.New()
|
||||
|
@ -300,7 +303,7 @@ func (suite *DriverSuite) TestWriteReadLargeStreams(c *check.C) {
|
|||
// reading with a given offset.
|
||||
func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
||||
filename := randomPath(32)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
chunkSize := int64(32)
|
||||
|
||||
|
@ -308,10 +311,10 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
|||
contentsChunk2 := randomContents(chunkSize)
|
||||
contentsChunk3 := randomContents(chunkSize)
|
||||
|
||||
err := suite.StorageDriver.PutContent(filename, append(append(contentsChunk1, contentsChunk2...), contentsChunk3...))
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, append(append(contentsChunk1, contentsChunk2...), contentsChunk3...))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
reader, err := suite.StorageDriver.ReadStream(filename, 0)
|
||||
reader, err := suite.StorageDriver.ReadStream(suite.ctx, filename, 0)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
@ -320,7 +323,7 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
|||
|
||||
c.Assert(readContents, check.DeepEquals, append(append(contentsChunk1, contentsChunk2...), contentsChunk3...))
|
||||
|
||||
reader, err = suite.StorageDriver.ReadStream(filename, chunkSize)
|
||||
reader, err = suite.StorageDriver.ReadStream(suite.ctx, filename, chunkSize)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
@ -329,7 +332,7 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
|||
|
||||
c.Assert(readContents, check.DeepEquals, append(contentsChunk2, contentsChunk3...))
|
||||
|
||||
reader, err = suite.StorageDriver.ReadStream(filename, chunkSize*2)
|
||||
reader, err = suite.StorageDriver.ReadStream(suite.ctx, filename, chunkSize*2)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
@ -338,7 +341,7 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
|||
c.Assert(readContents, check.DeepEquals, contentsChunk3)
|
||||
|
||||
// Ensure we get invalid offest for negative offsets.
|
||||
reader, err = suite.StorageDriver.ReadStream(filename, -1)
|
||||
reader, err = suite.StorageDriver.ReadStream(suite.ctx, filename, -1)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.InvalidOffsetError{})
|
||||
c.Assert(err.(storagedriver.InvalidOffsetError).Offset, check.Equals, int64(-1))
|
||||
c.Assert(err.(storagedriver.InvalidOffsetError).Path, check.Equals, filename)
|
||||
|
@ -346,7 +349,7 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
|||
|
||||
// Read past the end of the content and make sure we get a reader that
|
||||
// returns 0 bytes and io.EOF
|
||||
reader, err = suite.StorageDriver.ReadStream(filename, chunkSize*3)
|
||||
reader, err = suite.StorageDriver.ReadStream(suite.ctx, filename, chunkSize*3)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
@ -356,7 +359,7 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) {
|
|||
c.Assert(n, check.Equals, 0)
|
||||
|
||||
// Check the N-1 boundary condition, ensuring we get 1 byte then io.EOF.
|
||||
reader, err = suite.StorageDriver.ReadStream(filename, chunkSize*3-1)
|
||||
reader, err = suite.StorageDriver.ReadStream(suite.ctx, filename, chunkSize*3-1)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
@ -389,7 +392,7 @@ func (suite *DriverSuite) TestContinueStreamAppendSmall(c *check.C) {
|
|||
|
||||
func (suite *DriverSuite) testContinueStreamAppend(c *check.C, chunkSize int64) {
|
||||
filename := randomPath(32)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
contentsChunk1 := randomContents(chunkSize)
|
||||
contentsChunk2 := randomContents(chunkSize)
|
||||
|
@ -399,39 +402,39 @@ func (suite *DriverSuite) testContinueStreamAppend(c *check.C, chunkSize int64)
|
|||
|
||||
fullContents := append(append(contentsChunk1, contentsChunk2...), contentsChunk3...)
|
||||
|
||||
nn, err := suite.StorageDriver.WriteStream(filename, 0, bytes.NewReader(contentsChunk1))
|
||||
nn, err := suite.StorageDriver.WriteStream(suite.ctx, filename, 0, bytes.NewReader(contentsChunk1))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, int64(len(contentsChunk1)))
|
||||
|
||||
fi, err := suite.StorageDriver.Stat(filename)
|
||||
fi, err := suite.StorageDriver.Stat(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
c.Assert(fi.Size(), check.Equals, int64(len(contentsChunk1)))
|
||||
|
||||
nn, err = suite.StorageDriver.WriteStream(filename, fi.Size(), bytes.NewReader(contentsChunk2))
|
||||
nn, err = suite.StorageDriver.WriteStream(suite.ctx, filename, fi.Size(), bytes.NewReader(contentsChunk2))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, int64(len(contentsChunk2)))
|
||||
|
||||
fi, err = suite.StorageDriver.Stat(filename)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
c.Assert(fi.Size(), check.Equals, 2*chunkSize)
|
||||
|
||||
// Test re-writing the last chunk
|
||||
nn, err = suite.StorageDriver.WriteStream(filename, fi.Size()-chunkSize, bytes.NewReader(contentsChunk2))
|
||||
nn, err = suite.StorageDriver.WriteStream(suite.ctx, filename, fi.Size()-chunkSize, bytes.NewReader(contentsChunk2))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, int64(len(contentsChunk2)))
|
||||
|
||||
fi, err = suite.StorageDriver.Stat(filename)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
c.Assert(fi.Size(), check.Equals, 2*chunkSize)
|
||||
|
||||
nn, err = suite.StorageDriver.WriteStream(filename, fi.Size(), bytes.NewReader(fullContents[fi.Size():]))
|
||||
nn, err = suite.StorageDriver.WriteStream(suite.ctx, filename, fi.Size(), bytes.NewReader(fullContents[fi.Size():]))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, int64(len(fullContents[fi.Size():])))
|
||||
|
||||
received, err := suite.StorageDriver.GetContent(filename)
|
||||
received, err := suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(received, check.DeepEquals, fullContents)
|
||||
|
||||
|
@ -443,16 +446,16 @@ func (suite *DriverSuite) testContinueStreamAppend(c *check.C, chunkSize int64)
|
|||
fullContents = append(fullContents, zeroChunk...)
|
||||
fullContents = append(fullContents, contentsChunk4...)
|
||||
|
||||
nn, err = suite.StorageDriver.WriteStream(filename, int64(len(fullContents))-chunkSize, bytes.NewReader(contentsChunk4))
|
||||
nn, err = suite.StorageDriver.WriteStream(suite.ctx, filename, int64(len(fullContents))-chunkSize, bytes.NewReader(contentsChunk4))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, chunkSize)
|
||||
|
||||
fi, err = suite.StorageDriver.Stat(filename)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
c.Assert(fi.Size(), check.Equals, int64(len(fullContents)))
|
||||
|
||||
received, err = suite.StorageDriver.GetContent(filename)
|
||||
received, err = suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(len(received), check.Equals, len(fullContents))
|
||||
c.Assert(received[chunkSize*3:chunkSize*4], check.DeepEquals, zeroChunk)
|
||||
|
@ -460,7 +463,7 @@ func (suite *DriverSuite) testContinueStreamAppend(c *check.C, chunkSize int64)
|
|||
c.Assert(received, check.DeepEquals, fullContents)
|
||||
|
||||
// Ensure that negative offsets return correct error.
|
||||
nn, err = suite.StorageDriver.WriteStream(filename, -1, bytes.NewReader(zeroChunk))
|
||||
nn, err = suite.StorageDriver.WriteStream(suite.ctx, filename, -1, bytes.NewReader(zeroChunk))
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.InvalidOffsetError{})
|
||||
c.Assert(err.(storagedriver.InvalidOffsetError).Path, check.Equals, filename)
|
||||
|
@ -472,11 +475,11 @@ func (suite *DriverSuite) testContinueStreamAppend(c *check.C, chunkSize int64)
|
|||
func (suite *DriverSuite) TestReadNonexistentStream(c *check.C) {
|
||||
filename := randomPath(32)
|
||||
|
||||
_, err := suite.StorageDriver.ReadStream(filename, 0)
|
||||
_, err := suite.StorageDriver.ReadStream(suite.ctx, filename, 0)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
|
||||
_, err = suite.StorageDriver.ReadStream(filename, 64)
|
||||
_, err = suite.StorageDriver.ReadStream(suite.ctx, filename, 64)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -484,27 +487,27 @@ func (suite *DriverSuite) TestReadNonexistentStream(c *check.C) {
|
|||
// TestList checks the returned list of keys after populating a directory tree.
|
||||
func (suite *DriverSuite) TestList(c *check.C) {
|
||||
rootDirectory := "/" + randomFilename(int64(8+rand.Intn(8)))
|
||||
defer suite.StorageDriver.Delete(rootDirectory)
|
||||
defer suite.StorageDriver.Delete(suite.ctx, rootDirectory)
|
||||
|
||||
parentDirectory := rootDirectory + "/" + randomFilename(int64(8+rand.Intn(8)))
|
||||
childFiles := make([]string, 50)
|
||||
for i := 0; i < len(childFiles); i++ {
|
||||
childFile := parentDirectory + "/" + randomFilename(int64(8+rand.Intn(8)))
|
||||
childFiles[i] = childFile
|
||||
err := suite.StorageDriver.PutContent(childFile, randomContents(32))
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, childFile, randomContents(32))
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
sort.Strings(childFiles)
|
||||
|
||||
keys, err := suite.StorageDriver.List("/")
|
||||
keys, err := suite.StorageDriver.List(suite.ctx, "/")
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(keys, check.DeepEquals, []string{rootDirectory})
|
||||
|
||||
keys, err = suite.StorageDriver.List(rootDirectory)
|
||||
keys, err = suite.StorageDriver.List(suite.ctx, rootDirectory)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(keys, check.DeepEquals, []string{parentDirectory})
|
||||
|
||||
keys, err = suite.StorageDriver.List(parentDirectory)
|
||||
keys, err = suite.StorageDriver.List(suite.ctx, parentDirectory)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
sort.Strings(keys)
|
||||
|
@ -523,20 +526,20 @@ func (suite *DriverSuite) TestMove(c *check.C) {
|
|||
sourcePath := randomPath(32)
|
||||
destPath := randomPath(32)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(sourcePath))
|
||||
defer suite.StorageDriver.Delete(firstPart(destPath))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(sourcePath))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(destPath))
|
||||
|
||||
err := suite.StorageDriver.PutContent(sourcePath, contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, sourcePath, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.Move(sourcePath, destPath)
|
||||
err = suite.StorageDriver.Move(suite.ctx, sourcePath, destPath)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
received, err := suite.StorageDriver.GetContent(destPath)
|
||||
received, err := suite.StorageDriver.GetContent(suite.ctx, destPath)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(received, check.DeepEquals, contents)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(sourcePath)
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, sourcePath)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -549,23 +552,23 @@ func (suite *DriverSuite) TestMoveOverwrite(c *check.C) {
|
|||
sourceContents := randomContents(32)
|
||||
destContents := randomContents(64)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(sourcePath))
|
||||
defer suite.StorageDriver.Delete(firstPart(destPath))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(sourcePath))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(destPath))
|
||||
|
||||
err := suite.StorageDriver.PutContent(sourcePath, sourceContents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, sourcePath, sourceContents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.PutContent(destPath, destContents)
|
||||
err = suite.StorageDriver.PutContent(suite.ctx, destPath, destContents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.Move(sourcePath, destPath)
|
||||
err = suite.StorageDriver.Move(suite.ctx, sourcePath, destPath)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
received, err := suite.StorageDriver.GetContent(destPath)
|
||||
received, err := suite.StorageDriver.GetContent(suite.ctx, destPath)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(received, check.DeepEquals, sourceContents)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(sourcePath)
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, sourcePath)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -577,16 +580,16 @@ func (suite *DriverSuite) TestMoveNonexistent(c *check.C) {
|
|||
sourcePath := randomPath(32)
|
||||
destPath := randomPath(32)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(destPath))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(destPath))
|
||||
|
||||
err := suite.StorageDriver.PutContent(destPath, contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, destPath, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.Move(sourcePath, destPath)
|
||||
err = suite.StorageDriver.Move(suite.ctx, sourcePath, destPath)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
|
||||
received, err := suite.StorageDriver.GetContent(destPath)
|
||||
received, err := suite.StorageDriver.GetContent(suite.ctx, destPath)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(received, check.DeepEquals, contents)
|
||||
}
|
||||
|
@ -596,12 +599,12 @@ func (suite *DriverSuite) TestMoveInvalid(c *check.C) {
|
|||
contents := randomContents(32)
|
||||
|
||||
// Create a regular file.
|
||||
err := suite.StorageDriver.PutContent("/notadir", contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, "/notadir", contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer suite.StorageDriver.Delete("/notadir")
|
||||
defer suite.StorageDriver.Delete(suite.ctx, "/notadir")
|
||||
|
||||
// Now try to move a non-existent file under it.
|
||||
err = suite.StorageDriver.Move("/notadir/foo", "/notadir/bar")
|
||||
err = suite.StorageDriver.Move(suite.ctx, "/notadir/foo", "/notadir/bar")
|
||||
c.Assert(err, check.NotNil) // non-nil error
|
||||
}
|
||||
|
||||
|
@ -611,15 +614,15 @@ func (suite *DriverSuite) TestDelete(c *check.C) {
|
|||
filename := randomPath(32)
|
||||
contents := randomContents(32)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.Delete(filename)
|
||||
err = suite.StorageDriver.Delete(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(filename)
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -630,12 +633,12 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
|
|||
filename := randomPath(32)
|
||||
contents := randomContents(32)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
url, err := suite.StorageDriver.URLFor(filename, nil)
|
||||
url, err := suite.StorageDriver.URLFor(suite.ctx, filename, nil)
|
||||
if err == storagedriver.ErrUnsupportedMethod {
|
||||
return
|
||||
}
|
||||
|
@ -649,7 +652,7 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
c.Assert(read, check.DeepEquals, contents)
|
||||
|
||||
url, err = suite.StorageDriver.URLFor(filename, map[string]interface{}{"method": "HEAD"})
|
||||
url, err = suite.StorageDriver.URLFor(suite.ctx, filename, map[string]interface{}{"method": "HEAD"})
|
||||
if err == storagedriver.ErrUnsupportedMethod {
|
||||
return
|
||||
}
|
||||
|
@ -663,7 +666,7 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
|
|||
// TestDeleteNonexistent checks that removing a nonexistent key fails.
|
||||
func (suite *DriverSuite) TestDeleteNonexistent(c *check.C) {
|
||||
filename := randomPath(32)
|
||||
err := suite.StorageDriver.Delete(filename)
|
||||
err := suite.StorageDriver.Delete(suite.ctx, filename)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -676,42 +679,42 @@ func (suite *DriverSuite) TestDeleteFolder(c *check.C) {
|
|||
filename3 := randomPath(32)
|
||||
contents := randomContents(32)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(dirname))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(dirname))
|
||||
|
||||
err := suite.StorageDriver.PutContent(path.Join(dirname, filename1), contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, path.Join(dirname, filename1), contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.PutContent(path.Join(dirname, filename2), contents)
|
||||
err = suite.StorageDriver.PutContent(suite.ctx, path.Join(dirname, filename2), contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.PutContent(path.Join(dirname, filename3), contents)
|
||||
err = suite.StorageDriver.PutContent(suite.ctx, path.Join(dirname, filename3), contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.Delete(path.Join(dirname, filename1))
|
||||
err = suite.StorageDriver.Delete(suite.ctx, path.Join(dirname, filename1))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(path.Join(dirname, filename1))
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, path.Join(dirname, filename1))
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(path.Join(dirname, filename2))
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, path.Join(dirname, filename2))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(path.Join(dirname, filename3))
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, path.Join(dirname, filename3))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.Delete(dirname)
|
||||
err = suite.StorageDriver.Delete(suite.ctx, dirname)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(path.Join(dirname, filename1))
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, path.Join(dirname, filename1))
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(path.Join(dirname, filename2))
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, path.Join(dirname, filename2))
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(path.Join(dirname, filename3))
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, path.Join(dirname, filename3))
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
}
|
||||
|
@ -723,24 +726,24 @@ func (suite *DriverSuite) TestStatCall(c *check.C) {
|
|||
fileName := randomFilename(32)
|
||||
filePath := path.Join(dirPath, fileName)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(dirPath))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(dirPath))
|
||||
|
||||
// Call on non-existent file/dir, check error.
|
||||
fi, err := suite.StorageDriver.Stat(dirPath)
|
||||
fi, err := suite.StorageDriver.Stat(suite.ctx, dirPath)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
c.Assert(fi, check.IsNil)
|
||||
|
||||
fi, err = suite.StorageDriver.Stat(filePath)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, filePath)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err, check.FitsTypeOf, storagedriver.PathNotFoundError{})
|
||||
c.Assert(fi, check.IsNil)
|
||||
|
||||
err = suite.StorageDriver.PutContent(filePath, content)
|
||||
err = suite.StorageDriver.PutContent(suite.ctx, filePath, content)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
// Call on regular file, check results
|
||||
fi, err = suite.StorageDriver.Stat(filePath)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, filePath)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
c.Assert(fi.Path(), check.Equals, filePath)
|
||||
|
@ -751,9 +754,9 @@ func (suite *DriverSuite) TestStatCall(c *check.C) {
|
|||
// Sleep and modify the file
|
||||
time.Sleep(time.Second * 10)
|
||||
content = randomContents(4096)
|
||||
err = suite.StorageDriver.PutContent(filePath, content)
|
||||
err = suite.StorageDriver.PutContent(suite.ctx, filePath, content)
|
||||
c.Assert(err, check.IsNil)
|
||||
fi, err = suite.StorageDriver.Stat(filePath)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, filePath)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
time.Sleep(time.Second * 5) // allow changes to propagate (eventual consistency)
|
||||
|
@ -768,7 +771,7 @@ func (suite *DriverSuite) TestStatCall(c *check.C) {
|
|||
}
|
||||
|
||||
// Call on directory (do not check ModTime as dirs don't need to support it)
|
||||
fi, err = suite.StorageDriver.Stat(dirPath)
|
||||
fi, err = suite.StorageDriver.Stat(suite.ctx, dirPath)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(fi, check.NotNil)
|
||||
c.Assert(fi.Path(), check.Equals, dirPath)
|
||||
|
@ -784,15 +787,15 @@ func (suite *DriverSuite) TestPutContentMultipleTimes(c *check.C) {
|
|||
filename := randomPath(32)
|
||||
contents := randomContents(4096)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
contents = randomContents(2048) // upload a different, smaller file
|
||||
err = suite.StorageDriver.PutContent(filename, contents)
|
||||
err = suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
readContents, err := suite.StorageDriver.GetContent(filename)
|
||||
readContents, err := suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(readContents, check.DeepEquals, contents)
|
||||
}
|
||||
|
@ -810,9 +813,9 @@ func (suite *DriverSuite) TestConcurrentStreamReads(c *check.C) {
|
|||
filename := randomPath(32)
|
||||
contents := randomContents(filesize)
|
||||
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
@ -820,7 +823,7 @@ func (suite *DriverSuite) TestConcurrentStreamReads(c *check.C) {
|
|||
readContents := func() {
|
||||
defer wg.Done()
|
||||
offset := rand.Int63n(int64(len(contents)))
|
||||
reader, err := suite.StorageDriver.ReadStream(filename, offset)
|
||||
reader, err := suite.StorageDriver.ReadStream(suite.ctx, filename, offset)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
readContents, err := ioutil.ReadAll(reader)
|
||||
|
@ -872,7 +875,7 @@ func (suite *DriverSuite) TestEventualConsistency(c *check.C) {
|
|||
}
|
||||
|
||||
filename := randomPath(32)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
var offset int64
|
||||
var misswrites int
|
||||
|
@ -880,17 +883,17 @@ func (suite *DriverSuite) TestEventualConsistency(c *check.C) {
|
|||
|
||||
for i := 0; i < 1024; i++ {
|
||||
contents := randomContents(chunkSize)
|
||||
read, err := suite.StorageDriver.WriteStream(filename, offset, bytes.NewReader(contents))
|
||||
read, err := suite.StorageDriver.WriteStream(suite.ctx, filename, offset, bytes.NewReader(contents))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
fi, err := suite.StorageDriver.Stat(filename)
|
||||
fi, err := suite.StorageDriver.Stat(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
// We are most concerned with being able to read data as soon as Stat declares
|
||||
// it is uploaded. This is the strongest guarantee that some drivers (that guarantee
|
||||
// at best eventual consistency) absolutely need to provide.
|
||||
if fi.Size() == offset+chunkSize {
|
||||
reader, err := suite.StorageDriver.ReadStream(filename, offset)
|
||||
reader, err := suite.StorageDriver.ReadStream(suite.ctx, filename, offset)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
readContents, err := ioutil.ReadAll(reader)
|
||||
|
@ -937,15 +940,15 @@ func (suite *DriverSuite) benchmarkPutGetFiles(c *check.C, size int64) {
|
|||
parentDir := randomPath(8)
|
||||
defer func() {
|
||||
c.StopTimer()
|
||||
suite.StorageDriver.Delete(firstPart(parentDir))
|
||||
suite.StorageDriver.Delete(suite.ctx, firstPart(parentDir))
|
||||
}()
|
||||
|
||||
for i := 0; i < c.N; i++ {
|
||||
filename := path.Join(parentDir, randomPath(32))
|
||||
err := suite.StorageDriver.PutContent(filename, randomContents(size))
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, randomContents(size))
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
_, err = suite.StorageDriver.GetContent(filename)
|
||||
_, err = suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
}
|
||||
|
@ -975,16 +978,16 @@ func (suite *DriverSuite) benchmarkStreamFiles(c *check.C, size int64) {
|
|||
parentDir := randomPath(8)
|
||||
defer func() {
|
||||
c.StopTimer()
|
||||
suite.StorageDriver.Delete(firstPart(parentDir))
|
||||
suite.StorageDriver.Delete(suite.ctx, firstPart(parentDir))
|
||||
}()
|
||||
|
||||
for i := 0; i < c.N; i++ {
|
||||
filename := path.Join(parentDir, randomPath(32))
|
||||
written, err := suite.StorageDriver.WriteStream(filename, 0, bytes.NewReader(randomContents(size)))
|
||||
written, err := suite.StorageDriver.WriteStream(suite.ctx, filename, 0, bytes.NewReader(randomContents(size)))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(written, check.Equals, size)
|
||||
|
||||
rc, err := suite.StorageDriver.ReadStream(filename, 0)
|
||||
rc, err := suite.StorageDriver.ReadStream(suite.ctx, filename, 0)
|
||||
c.Assert(err, check.IsNil)
|
||||
rc.Close()
|
||||
}
|
||||
|
@ -1004,17 +1007,17 @@ func (suite *DriverSuite) benchmarkListFiles(c *check.C, numFiles int64) {
|
|||
parentDir := randomPath(8)
|
||||
defer func() {
|
||||
c.StopTimer()
|
||||
suite.StorageDriver.Delete(firstPart(parentDir))
|
||||
suite.StorageDriver.Delete(suite.ctx, firstPart(parentDir))
|
||||
}()
|
||||
|
||||
for i := int64(0); i < numFiles; i++ {
|
||||
err := suite.StorageDriver.PutContent(path.Join(parentDir, randomPath(32)), nil)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, path.Join(parentDir, randomPath(32)), nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
c.ResetTimer()
|
||||
for i := 0; i < c.N; i++ {
|
||||
files, err := suite.StorageDriver.List(parentDir)
|
||||
files, err := suite.StorageDriver.List(suite.ctx, parentDir)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(int64(len(files)), check.Equals, numFiles)
|
||||
}
|
||||
|
@ -1033,17 +1036,17 @@ func (suite *DriverSuite) BenchmarkDelete50Files(c *check.C) {
|
|||
func (suite *DriverSuite) benchmarkDeleteFiles(c *check.C, numFiles int64) {
|
||||
for i := 0; i < c.N; i++ {
|
||||
parentDir := randomPath(8)
|
||||
defer suite.StorageDriver.Delete(firstPart(parentDir))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(parentDir))
|
||||
|
||||
c.StopTimer()
|
||||
for j := int64(0); j < numFiles; j++ {
|
||||
err := suite.StorageDriver.PutContent(path.Join(parentDir, randomPath(32)), nil)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, path.Join(parentDir, randomPath(32)), nil)
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
c.StartTimer()
|
||||
|
||||
// This is the operation we're benchmarking
|
||||
err := suite.StorageDriver.Delete(firstPart(parentDir))
|
||||
err := suite.StorageDriver.Delete(suite.ctx, firstPart(parentDir))
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
}
|
||||
|
@ -1055,7 +1058,7 @@ func (suite *DriverSuite) testFileStreams(c *check.C, size int64) {
|
|||
defer tf.Close()
|
||||
|
||||
filename := randomPath(32)
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
contents := randomContents(size)
|
||||
|
||||
|
@ -1065,11 +1068,11 @@ func (suite *DriverSuite) testFileStreams(c *check.C, size int64) {
|
|||
tf.Sync()
|
||||
tf.Seek(0, os.SEEK_SET)
|
||||
|
||||
nn, err := suite.StorageDriver.WriteStream(filename, 0, tf)
|
||||
nn, err := suite.StorageDriver.WriteStream(suite.ctx, filename, 0, tf)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, size)
|
||||
|
||||
reader, err := suite.StorageDriver.ReadStream(filename, 0)
|
||||
reader, err := suite.StorageDriver.ReadStream(suite.ctx, filename, 0)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
@ -1080,25 +1083,25 @@ func (suite *DriverSuite) testFileStreams(c *check.C, size int64) {
|
|||
}
|
||||
|
||||
func (suite *DriverSuite) writeReadCompare(c *check.C, filename string, contents []byte) {
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
err := suite.StorageDriver.PutContent(filename, contents)
|
||||
err := suite.StorageDriver.PutContent(suite.ctx, filename, contents)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
readContents, err := suite.StorageDriver.GetContent(filename)
|
||||
readContents, err := suite.StorageDriver.GetContent(suite.ctx, filename)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
c.Assert(readContents, check.DeepEquals, contents)
|
||||
}
|
||||
|
||||
func (suite *DriverSuite) writeReadCompareStreams(c *check.C, filename string, contents []byte) {
|
||||
defer suite.StorageDriver.Delete(firstPart(filename))
|
||||
defer suite.StorageDriver.Delete(suite.ctx, firstPart(filename))
|
||||
|
||||
nn, err := suite.StorageDriver.WriteStream(filename, 0, bytes.NewReader(contents))
|
||||
nn, err := suite.StorageDriver.WriteStream(suite.ctx, filename, 0, bytes.NewReader(contents))
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(nn, check.Equals, int64(len(contents)))
|
||||
|
||||
reader, err := suite.StorageDriver.ReadStream(filename, 0)
|
||||
reader, err := suite.StorageDriver.ReadStream(suite.ctx, filename, 0)
|
||||
c.Assert(err, check.IsNil)
|
||||
defer reader.Close()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue