Use designated error classes for common bucket and object errors (#691)
This commit is contained in:
parent
7e40caafcd
commit
8c56198090
@ -73,7 +73,7 @@ func upload(ctx context.Context, bs buckets.Store, src fpath.FPath, dst fpath.FP
|
||||
|
||||
o, err := bs.GetObjectStore(ctx, dst.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, dst)
|
||||
}
|
||||
|
||||
r := io.Reader(f)
|
||||
@ -113,12 +113,12 @@ func download(ctx context.Context, bs buckets.Store, src fpath.FPath, dst fpath.
|
||||
|
||||
o, err := bs.GetObjectStore(ctx, src.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, src)
|
||||
}
|
||||
|
||||
rr, _, err := o.Get(ctx, src.Path())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, src)
|
||||
}
|
||||
|
||||
r, err := rr.Range(ctx, 0, rr.Size())
|
||||
@ -177,12 +177,12 @@ func copy(ctx context.Context, bs buckets.Store, src fpath.FPath, dst fpath.FPat
|
||||
|
||||
o, err := bs.GetObjectStore(ctx, src.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, src)
|
||||
}
|
||||
|
||||
rr, _, err := o.Get(ctx, src.Path())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, src)
|
||||
}
|
||||
|
||||
r, err := rr.Range(ctx, 0, rr.Size())
|
||||
@ -201,7 +201,7 @@ func copy(ctx context.Context, bs buckets.Store, src fpath.FPath, dst fpath.FPat
|
||||
if dst.Bucket() != src.Bucket() {
|
||||
o, err = bs.GetObjectStore(ctx, dst.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, dst)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,9 @@ func list(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("No bucket specified, use format sj://bucket/")
|
||||
}
|
||||
|
||||
return listFiles(ctx, bs, src, false)
|
||||
err = listFiles(ctx, bs, src, false)
|
||||
|
||||
return convertError(err, src)
|
||||
}
|
||||
|
||||
startAfter := ""
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"storj.io/storj/internal/fpath"
|
||||
"storj.io/storj/pkg/process"
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -51,7 +50,7 @@ func makeBucket(cmd *cobra.Command, args []string) error {
|
||||
if err == nil {
|
||||
return fmt.Errorf("Bucket already exists")
|
||||
}
|
||||
if !storage.ErrKeyNotFound.Has(err) {
|
||||
if !storj.ErrBucketNotFound.Has(err) {
|
||||
return err
|
||||
}
|
||||
_, err = bs.Put(ctx, dst.Bucket(), storj.Cipher(cfg.PathEncType))
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"storj.io/storj/pkg/storage/objects"
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -63,7 +62,7 @@ func mountBucket(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
store, err := bs.GetObjectStore(ctx, src.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, src)
|
||||
}
|
||||
|
||||
nfs := pathfs.NewPathNodeFs(newStorjFS(ctx, store), nil)
|
||||
@ -133,7 +132,7 @@ func (sf *storjFS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse
|
||||
}
|
||||
|
||||
metadata, err := sf.store.Meta(sf.ctx, name)
|
||||
if err != nil && !storage.ErrKeyNotFound.Has(err) {
|
||||
if err != nil && !storj.ErrObjectNotFound.Has(err) {
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
|
||||
@ -144,7 +143,7 @@ func (sf *storjFS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
|
||||
// when at least one element has this prefix then it's directory
|
||||
// if exactly one element has this prefix then it's directory
|
||||
if len(items) == 1 {
|
||||
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK
|
||||
}
|
||||
@ -269,7 +268,7 @@ func (sf *storjFS) Unlink(name string, context *fuse.Context) (code fuse.Status)
|
||||
|
||||
err := sf.store.Delete(sf.ctx, name)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
if storj.ErrObjectNotFound.Has(err) {
|
||||
return fuse.ENOENT
|
||||
}
|
||||
return fuse.EIO
|
||||
@ -327,7 +326,7 @@ func (f *storjFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.
|
||||
|
||||
reader, err := f.getReader(off)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
if storj.ErrObjectNotFound.Has(err) {
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
return nil, fuse.EIO
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"storj.io/storj/internal/fpath"
|
||||
"storj.io/storj/pkg/process"
|
||||
"storj.io/storj/pkg/storage/meta"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -47,17 +46,9 @@ func deleteBucket(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = bs.Get(ctx, dst.Bucket())
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
return fmt.Errorf("Bucket not found: %s", dst.Bucket())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
o, err := bs.GetObjectStore(ctx, dst.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, dst)
|
||||
}
|
||||
|
||||
items, _, err := o.List(ctx, "", "", "", true, 1, meta.None)
|
||||
@ -71,7 +62,7 @@ func deleteBucket(cmd *cobra.Command, args []string) error {
|
||||
|
||||
err = bs.Delete(ctx, dst.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, dst)
|
||||
}
|
||||
|
||||
fmt.Printf("Bucket %s deleted\n", dst.Bucket())
|
||||
|
@ -43,12 +43,12 @@ func deleteObject(cmd *cobra.Command, args []string) error {
|
||||
|
||||
o, err := bs.GetObjectStore(ctx, dst.Bucket())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, dst)
|
||||
}
|
||||
|
||||
err = o.Delete(ctx, dst.Path())
|
||||
if err != nil {
|
||||
return err
|
||||
return convertError(err, dst)
|
||||
}
|
||||
|
||||
fmt.Printf("Deleted %s\n", dst)
|
||||
|
@ -5,13 +5,16 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"storj.io/storj/internal/fpath"
|
||||
"storj.io/storj/pkg/cfgstruct"
|
||||
"storj.io/storj/pkg/miniogw"
|
||||
"storj.io/storj/pkg/storage/buckets"
|
||||
"storj.io/storj/pkg/storj"
|
||||
)
|
||||
|
||||
const defaultConfDir = "$HOME/.storj/uplink"
|
||||
@ -51,3 +54,15 @@ func (c *Config) BucketStore(ctx context.Context) (buckets.Store, error) {
|
||||
|
||||
return c.GetBucketStore(ctx, identity)
|
||||
}
|
||||
|
||||
func convertError(err error, path fpath.FPath) error {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
return fmt.Errorf("Bucket not found: %s", path.Bucket())
|
||||
}
|
||||
|
||||
if storj.ErrObjectNotFound.Has(err) {
|
||||
return fmt.Errorf("Object not found: %s", path.String())
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"storj.io/storj/pkg/storage/segments"
|
||||
"storj.io/storj/pkg/storage/streams"
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -67,7 +66,7 @@ func TestBucketsBasic(t *testing.T) {
|
||||
|
||||
// Check that the bucket cannot be get explicitly
|
||||
bucket, err = db.GetBucket(ctx, TestBucket)
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
})
|
||||
}
|
||||
|
||||
@ -105,7 +104,7 @@ func TestBucketsReadNewWayWriteOldWay(t *testing.T) {
|
||||
|
||||
// (New API) Check that the bucket cannot be get explicitly
|
||||
bucket, err = db.GetBucket(ctx, TestBucket)
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
})
|
||||
}
|
||||
|
||||
@ -144,7 +143,7 @@ func TestBucketsReadOldWayWriteNewWay(t *testing.T) {
|
||||
|
||||
// (Old API) Check that the bucket cannot be get explicitly
|
||||
_, err = db.buckets.Get(ctx, TestBucket)
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -80,12 +80,7 @@ func (db *DB) DeleteObject(ctx context.Context, bucket string, path storj.Path)
|
||||
return err
|
||||
}
|
||||
|
||||
err = store.Delete(ctx, path)
|
||||
if objects.NoPathError.Has(err) {
|
||||
return storage.ErrEmptyKey.Wrap(err)
|
||||
}
|
||||
|
||||
return err
|
||||
return store.Delete(ctx, path)
|
||||
}
|
||||
|
||||
// ModifyPendingObject creates an interface for updating a partially uploaded object
|
||||
@ -180,6 +175,9 @@ func (db *DB) getInfo(ctx context.Context, prefix string, bucket string, path st
|
||||
|
||||
pointer, _, err := db.pointers.Get(ctx, prefix+encryptedPath)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrObjectNotFound.Wrap(err)
|
||||
}
|
||||
return object{}, storj.Object{}, err
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,10 @@ func TestGetObject(t *testing.T) {
|
||||
assert.True(t, storage.ErrEmptyKey.Has(err))
|
||||
|
||||
_, err = db.GetObject(ctx, "non-existing-bucket", "test-file")
|
||||
// TODO: Should return storj.ErrBucketNotFound
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
|
||||
_, err = db.GetObject(ctx, bucket.Name, "non-existing-file")
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrObjectNotFound.Has(err))
|
||||
|
||||
object, err := db.GetObject(ctx, bucket.Name, "test-file")
|
||||
if assert.NoError(t, err) {
|
||||
@ -85,11 +84,10 @@ func TestGetObjectStream(t *testing.T) {
|
||||
assert.True(t, storage.ErrEmptyKey.Has(err))
|
||||
|
||||
_, err = db.GetObjectStream(ctx, "non-existing-bucket", "test-file")
|
||||
// TODO: Should return storj.ErrBucketNotFound
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
|
||||
_, err = db.GetObject(ctx, bucket.Name, "non-existing-file")
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrObjectNotFound.Has(err))
|
||||
|
||||
stream, err := db.GetObjectStream(ctx, bucket.Name, "empty-file")
|
||||
if assert.NoError(t, err) {
|
||||
@ -146,14 +144,13 @@ func TestDeleteObject(t *testing.T) {
|
||||
assert.True(t, storj.ErrNoBucket.Has(err))
|
||||
|
||||
err = db.DeleteObject(ctx, bucket.Name, "")
|
||||
assert.True(t, storage.ErrEmptyKey.Has(err))
|
||||
assert.True(t, storj.ErrNoPath.Has(err))
|
||||
|
||||
_ = db.DeleteObject(ctx, "non-existing-bucket", "test-file")
|
||||
// TODO: Currently returns minio.BucketNotFound, should return storj.ErrBucketNotFound
|
||||
// assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
err = db.DeleteObject(ctx, "non-existing-bucket", "test-file")
|
||||
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
||||
|
||||
err = db.DeleteObject(ctx, bucket.Name, "non-existing-file")
|
||||
assert.True(t, storage.ErrKeyNotFound.Has(err))
|
||||
assert.True(t, storj.ErrObjectNotFound.Has(err))
|
||||
|
||||
err = db.DeleteObject(ctx, bucket.Name, "test-file")
|
||||
assert.NoError(t, err)
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"storj.io/storj/pkg/storage/objects"
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -65,50 +64,46 @@ type storjObjects struct {
|
||||
|
||||
func (s *storjObjects) DeleteBucket(ctx context.Context, bucket string) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
_, err = s.storj.bs.Get(ctx, bucket)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
return minio.BucketNotFound{Bucket: bucket}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
return convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
|
||||
items, _, err := o.List(ctx, "", "", "", true, 1, meta.None)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(items) > 0 {
|
||||
return minio.BucketNotEmpty{Bucket: bucket}
|
||||
}
|
||||
return s.storj.bs.Delete(ctx, bucket)
|
||||
|
||||
err = s.storj.bs.Delete(ctx, bucket)
|
||||
|
||||
return convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
|
||||
func (s *storjObjects) DeleteObject(ctx context.Context, bucket, object string) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
return convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
|
||||
err = o.Delete(ctx, object)
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = minio.ObjectNotFound{Bucket: bucket, Object: object}
|
||||
}
|
||||
return err
|
||||
|
||||
return convertObjectNotFoundError(err, bucket, object)
|
||||
}
|
||||
|
||||
func (s *storjObjects) GetBucketInfo(ctx context.Context, bucket string) (
|
||||
bucketInfo minio.BucketInfo, err error) {
|
||||
func (s *storjObjects) GetBucketInfo(ctx context.Context, bucket string) (bucketInfo minio.BucketInfo, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
meta, err := s.storj.bs.Get(ctx, bucket)
|
||||
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
return bucketInfo, minio.BucketNotFound{Bucket: bucket}
|
||||
}
|
||||
return bucketInfo, err
|
||||
return minio.BucketInfo{}, convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
|
||||
return minio.BucketInfo{Name: bucket, Created: meta.Created}, nil
|
||||
@ -116,18 +111,18 @@ func (s *storjObjects) GetBucketInfo(ctx context.Context, bucket string) (
|
||||
|
||||
func (s *storjObjects) getObject(ctx context.Context, bucket, object string) (rr ranger.Ranger, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
|
||||
rr, _, err = o.Get(ctx, object)
|
||||
|
||||
return rr, err
|
||||
return rr, convertObjectNotFoundError(err, bucket, object)
|
||||
}
|
||||
|
||||
func (s *storjObjects) GetObject(ctx context.Context, bucket, object string,
|
||||
startOffset int64, length int64, writer io.Writer, etag string) (err error) {
|
||||
func (s *storjObjects) GetObject(ctx context.Context, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
rr, err := s.getObject(ctx, bucket, object)
|
||||
@ -150,24 +145,19 @@ func (s *storjObjects) GetObject(ctx context.Context, bucket, object string,
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *storjObjects) GetObjectInfo(ctx context.Context, bucket,
|
||||
object string) (objInfo minio.ObjectInfo, err error) {
|
||||
func (s *storjObjects) GetObjectInfo(ctx context.Context, bucket, object string) (objInfo minio.ObjectInfo, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return minio.ObjectInfo{}, err
|
||||
return minio.ObjectInfo{}, convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
|
||||
m, err := o.Meta(ctx, object)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
return objInfo, minio.ObjectNotFound{
|
||||
Bucket: bucket,
|
||||
Object: object,
|
||||
}
|
||||
}
|
||||
|
||||
return objInfo, err
|
||||
return objInfo, convertObjectNotFoundError(err, bucket, object)
|
||||
}
|
||||
|
||||
return minio.ObjectInfo{
|
||||
Name: object,
|
||||
Bucket: bucket,
|
||||
@ -179,11 +169,12 @@ func (s *storjObjects) GetObjectInfo(ctx context.Context, bucket,
|
||||
}, err
|
||||
}
|
||||
|
||||
func (s *storjObjects) ListBuckets(ctx context.Context) (
|
||||
bucketItems []minio.BucketInfo, err error) {
|
||||
func (s *storjObjects) ListBuckets(ctx context.Context) (bucketItems []minio.BucketInfo, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
startAfter := ""
|
||||
var items []buckets.ListItem
|
||||
|
||||
for {
|
||||
moreItems, more, err := s.storj.bs.List(ctx, startAfter, "", 0)
|
||||
if err != nil {
|
||||
@ -195,11 +186,13 @@ func (s *storjObjects) ListBuckets(ctx context.Context) (
|
||||
}
|
||||
startAfter = moreItems[len(moreItems)-1].Bucket
|
||||
}
|
||||
|
||||
bucketItems = make([]minio.BucketInfo, len(items))
|
||||
for i, item := range items {
|
||||
bucketItems[i].Name = item.Bucket
|
||||
bucketItems[i].Created = item.Meta.Created
|
||||
}
|
||||
|
||||
return bucketItems, err
|
||||
}
|
||||
|
||||
@ -217,7 +210,7 @@ func (s *storjObjects) ListObjects(ctx context.Context, bucket, prefix, marker,
|
||||
var prefixes []string
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return minio.ListObjectsInfo{}, err
|
||||
return minio.ListObjectsInfo{}, convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
items, more, err := o.List(ctx, prefix, startAfter, "", recursive, maxKeys, meta.All)
|
||||
if err != nil {
|
||||
@ -282,7 +275,7 @@ func (s *storjObjects) ListObjectsV2(ctx context.Context, bucket, prefix, contin
|
||||
var prefixes []string
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return minio.ListObjectsV2Info{ContinuationToken: continuationToken}, err
|
||||
return minio.ListObjectsV2Info{ContinuationToken: continuationToken}, convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
items, more, err := o.List(ctx, prefix, startAfterPath, "", recursive, maxKeys, meta.All)
|
||||
if err != nil {
|
||||
@ -340,15 +333,14 @@ func (s *storjObjects) MakeBucketWithLocation(ctx context.Context, bucket string
|
||||
if err == nil {
|
||||
return minio.BucketAlreadyExists{Bucket: bucket}
|
||||
}
|
||||
if !storage.ErrKeyNotFound.Has(err) {
|
||||
if !storj.ErrBucketNotFound.Has(err) {
|
||||
return err
|
||||
}
|
||||
_, err = s.storj.bs.Put(ctx, bucket, s.storj.pathCipher)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *storjObjects) CopyObject(ctx context.Context, srcBucket, srcObject, destBucket,
|
||||
destObject string, srcInfo minio.ObjectInfo) (objInfo minio.ObjectInfo, err error) {
|
||||
func (s *storjObjects) CopyObject(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, srcInfo minio.ObjectInfo) (objInfo minio.ObjectInfo, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
rr, err := s.getObject(ctx, srcBucket, srcObject)
|
||||
@ -371,15 +363,14 @@ func (s *storjObjects) CopyObject(ctx context.Context, srcBucket, srcObject, des
|
||||
return s.putObject(ctx, destBucket, destObject, r, serMetaInfo)
|
||||
}
|
||||
|
||||
func (s *storjObjects) putObject(ctx context.Context, bucket, object string, r io.Reader,
|
||||
meta objects.SerializableMeta) (objInfo minio.ObjectInfo, err error) {
|
||||
func (s *storjObjects) putObject(ctx context.Context, bucket, object string, r io.Reader, meta objects.SerializableMeta) (objInfo minio.ObjectInfo, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
// setting zero value means the object never expires
|
||||
expTime := time.Time{}
|
||||
o, err := s.storj.bs.GetObjectStore(ctx, bucket)
|
||||
if err != nil {
|
||||
return minio.ObjectInfo{}, err
|
||||
return minio.ObjectInfo{}, convertBucketNotFoundError(err, bucket)
|
||||
}
|
||||
m, err := o.Put(ctx, object, r, meta, expTime)
|
||||
return minio.ObjectInfo{
|
||||
@ -393,9 +384,7 @@ func (s *storjObjects) putObject(ctx context.Context, bucket, object string, r i
|
||||
}, err
|
||||
}
|
||||
|
||||
func (s *storjObjects) PutObject(ctx context.Context, bucket, object string,
|
||||
data *hash.Reader, metadata map[string]string) (objInfo minio.ObjectInfo,
|
||||
err error) {
|
||||
func (s *storjObjects) PutObject(ctx context.Context, bucket, object string, data *hash.Reader, metadata map[string]string) (objInfo minio.ObjectInfo, err error) {
|
||||
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
tempContType := metadata["content-type"]
|
||||
@ -417,3 +406,17 @@ func (s *storjObjects) Shutdown(ctx context.Context) (err error) {
|
||||
func (s *storjObjects) StorageInfo(context.Context) minio.StorageInfo {
|
||||
return minio.StorageInfo{}
|
||||
}
|
||||
|
||||
func convertBucketNotFoundError(err error, bucket string) error {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
return minio.BucketNotFound{Bucket: bucket}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func convertObjectNotFoundError(err error, bucket, object string) error {
|
||||
if storj.ErrObjectNotFound.Has(err) {
|
||||
return minio.ObjectNotFound{Bucket: bucket, Object: object}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
mock_buckets "storj.io/storj/pkg/storage/buckets/mocks"
|
||||
"storj.io/storj/pkg/storage/meta"
|
||||
"storj.io/storj/pkg/storage/objects"
|
||||
"storj.io/storj/storage"
|
||||
"storj.io/storj/pkg/storj"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -421,7 +421,6 @@ func TestDeleteBucket(t *testing.T) {
|
||||
itemsInBucket := make([]objects.ListItem, 1)
|
||||
itemsInBucket[0] = objects.ListItem{Path: "path1", Meta: objects.Meta{}}
|
||||
|
||||
exp := time.Unix(0, 0).UTC()
|
||||
var noItemsInBucket []objects.ListItem
|
||||
|
||||
for i, example := range []struct {
|
||||
@ -432,13 +431,12 @@ func TestDeleteBucket(t *testing.T) {
|
||||
errString string
|
||||
}{
|
||||
{"mybucket", noItemsInBucket, nil, nil, ""},
|
||||
{"mybucket", noItemsInBucket, storage.ErrKeyNotFound.New("mybucket"), nil, "Bucket not found: mybucket"},
|
||||
{"mybucket", noItemsInBucket, storj.ErrBucketNotFound.New("mybucket"), nil, "Bucket not found: mybucket"},
|
||||
{"mybucket", itemsInBucket, nil, minio.BucketNotEmpty{Bucket: "mybucket"}, "Bucket not empty: mybucket"},
|
||||
} {
|
||||
errTag := fmt.Sprintf("Test case #%d", i)
|
||||
mockBS.EXPECT().Get(gomock.Any(), gomock.Any()).Return(buckets.Meta{Created: exp}, example.bucketStatus)
|
||||
if !storage.ErrKeyNotFound.Has(example.bucketStatus) {
|
||||
mockBS.EXPECT().GetObjectStore(gomock.Any(), example.bucket).Return(mockOS, nil)
|
||||
mockBS.EXPECT().GetObjectStore(gomock.Any(), example.bucket).Return(mockOS, example.bucketStatus)
|
||||
if !storj.ErrBucketNotFound.Has(example.bucketStatus) {
|
||||
mockOS.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
|
||||
gomock.Any(), gomock.Any(), gomock.Any()).Return(example.items, false, example.err)
|
||||
if len(example.items) == 0 {
|
||||
@ -502,11 +500,11 @@ func TestMakeBucketWithLocation(t *testing.T) {
|
||||
bucketStatus error
|
||||
}{
|
||||
{"mybucket", exp, minio.BucketAlreadyExists{Bucket: "mybucket"}, nil},
|
||||
{"mybucket", exp, nil, storage.ErrKeyNotFound.New("mybucket")},
|
||||
{"mybucket", exp, nil, storj.ErrBucketNotFound.New("mybucket")},
|
||||
} {
|
||||
errTag := fmt.Sprintf("Test case #%d", i)
|
||||
mockBS.EXPECT().Get(gomock.Any(), gomock.Any()).Return(buckets.Meta{Created: exp}, example.bucketStatus)
|
||||
if storage.ErrKeyNotFound.Has(example.bucketStatus) {
|
||||
if storj.ErrBucketNotFound.Has(example.bucketStatus) {
|
||||
mockBS.EXPECT().Put(gomock.Any(), example.bucket, gomock.Any()).Return(buckets.Meta{Created: example.meta}, nil)
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ func (o *prefixedObjStore) Meta(ctx context.Context, path storj.Path) (meta obje
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return objects.Meta{}, objects.NoPathError.New("")
|
||||
return objects.Meta{}, storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
return o.store.Meta(ctx, storj.JoinPaths(o.prefix, path))
|
||||
@ -32,7 +32,7 @@ func (o *prefixedObjStore) Get(ctx context.Context, path storj.Path) (rr ranger.
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return nil, objects.Meta{}, objects.NoPathError.New("")
|
||||
return nil, objects.Meta{}, storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
return o.store.Get(ctx, storj.JoinPaths(o.prefix, path))
|
||||
@ -42,7 +42,7 @@ func (o *prefixedObjStore) Put(ctx context.Context, path storj.Path, data io.Rea
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return objects.Meta{}, objects.NoPathError.New("")
|
||||
return objects.Meta{}, storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
return o.store.Put(ctx, storj.JoinPaths(o.prefix, path), data, metadata, expiration)
|
||||
@ -52,7 +52,7 @@ func (o *prefixedObjStore) Delete(ctx context.Context, path storj.Path) (err err
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return objects.NoPathError.New("")
|
||||
return storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
return o.store.Delete(ctx, storj.JoinPaths(o.prefix, path))
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
minio "github.com/minio/minio/cmd"
|
||||
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
||||
|
||||
"storj.io/storj/pkg/encryption"
|
||||
@ -65,7 +64,7 @@ func (b *BucketStore) GetObjectStore(ctx context.Context, bucket string) (object
|
||||
m, err := b.Get(ctx, bucket)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
return nil, minio.BucketNotFound{Bucket: bucket}
|
||||
err = storj.ErrBucketNotFound.Wrap(err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@ -86,8 +85,12 @@ func (b *BucketStore) Get(ctx context.Context, bucket string) (meta Meta, err er
|
||||
|
||||
objMeta, err := b.store.Meta(ctx, bucket)
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrBucketNotFound.Wrap(err)
|
||||
}
|
||||
return Meta{}, err
|
||||
}
|
||||
|
||||
return convertMeta(objMeta)
|
||||
}
|
||||
|
||||
@ -123,7 +126,13 @@ func (b *BucketStore) Delete(ctx context.Context, bucket string) (err error) {
|
||||
return storj.ErrNoBucket.New("")
|
||||
}
|
||||
|
||||
return b.store.Delete(ctx, bucket)
|
||||
err = b.store.Delete(ctx, bucket)
|
||||
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrBucketNotFound.Wrap(err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// List calls objects store List
|
||||
|
@ -9,20 +9,17 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/zeebo/errs"
|
||||
"go.uber.org/zap"
|
||||
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
||||
|
||||
"storj.io/storj/pkg/ranger"
|
||||
"storj.io/storj/pkg/storage/streams"
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
var mon = monkit.Package()
|
||||
|
||||
// NoPathError is an error class for missing object path
|
||||
var NoPathError = errs.Class("no object path specified")
|
||||
|
||||
// Meta is the full object metadata
|
||||
type Meta struct {
|
||||
SerializableMeta
|
||||
@ -62,10 +59,15 @@ func (o *objStore) Meta(ctx context.Context, path storj.Path) (meta Meta, err er
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return Meta{}, NoPathError.New("")
|
||||
return Meta{}, storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
m, err := o.store.Meta(ctx, path, o.pathCipher)
|
||||
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrObjectNotFound.Wrap(err)
|
||||
}
|
||||
|
||||
return convertMeta(m), err
|
||||
}
|
||||
|
||||
@ -74,10 +76,15 @@ func (o *objStore) Get(ctx context.Context, path storj.Path) (
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return nil, Meta{}, NoPathError.New("")
|
||||
return nil, Meta{}, storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
rr, m, err := o.store.Get(ctx, path, o.pathCipher)
|
||||
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrObjectNotFound.Wrap(err)
|
||||
}
|
||||
|
||||
return rr, convertMeta(m), err
|
||||
}
|
||||
|
||||
@ -85,7 +92,7 @@ func (o *objStore) Put(ctx context.Context, path storj.Path, data io.Reader, met
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return Meta{}, NoPathError.New("")
|
||||
return Meta{}, storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
// TODO(kaloyan): autodetect content type
|
||||
@ -103,10 +110,16 @@ func (o *objStore) Delete(ctx context.Context, path storj.Path) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(path) == 0 {
|
||||
return NoPathError.New("")
|
||||
return storj.ErrNoPath.New("")
|
||||
}
|
||||
|
||||
return o.store.Delete(ctx, path, o.pathCipher)
|
||||
err = o.store.Delete(ctx, path, o.pathCipher)
|
||||
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrObjectNotFound.Wrap(err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o *objStore) List(ctx context.Context, prefix, startAfter, endBefore storj.Path, recursive bool, limit int, metaFlags uint32) (
|
||||
|
@ -9,8 +9,19 @@ import (
|
||||
"github.com/zeebo/errs"
|
||||
)
|
||||
|
||||
// ErrNoBucket is an error class for using empty bucket name
|
||||
var ErrNoBucket = errs.Class("no bucket specified")
|
||||
var (
|
||||
// ErrNoBucket is an error class for using empty bucket name
|
||||
ErrNoBucket = errs.Class("no bucket specified")
|
||||
|
||||
// ErrNoPath is an error class for using empty path
|
||||
ErrNoPath = errs.Class("no path specified")
|
||||
|
||||
// ErrBucketNotFound is an error class for non-existing bucket
|
||||
ErrBucketNotFound = errs.Class("bucket not found")
|
||||
|
||||
// ErrObjectNotFound is an error class for non-existing object
|
||||
ErrObjectNotFound = errs.Class("object not found")
|
||||
)
|
||||
|
||||
// Bucket contains information about a specific bucket
|
||||
type Bucket struct {
|
||||
|
Loading…
Reference in New Issue
Block a user