2018-08-16 15:32:28 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package buckets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/ranger"
|
|
|
|
"storj.io/storj/pkg/storage/objects"
|
2018-10-25 21:28:16 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-08-16 15:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type prefixedObjStore struct {
|
|
|
|
o objects.Store
|
|
|
|
prefix string
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
func (o *prefixedObjStore) Meta(ctx context.Context, path storj.Path) (meta objects.Meta, err error) {
|
2018-08-16 15:32:28 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-09-09 18:31:26 +01:00
|
|
|
|
|
|
|
if len(path) == 0 {
|
|
|
|
return objects.Meta{}, objects.NoPathError.New("")
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
m, err := o.o.Meta(ctx, storj.JoinPaths(o.prefix, path))
|
2018-08-16 15:32:28 +01:00
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
func (o *prefixedObjStore) Get(ctx context.Context, path storj.Path) (rr ranger.Ranger, meta objects.Meta, err error) {
|
2018-08-16 15:32:28 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-09-09 18:31:26 +01:00
|
|
|
|
|
|
|
if len(path) == 0 {
|
|
|
|
return nil, objects.Meta{}, objects.NoPathError.New("")
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
rr, m, err := o.o.Get(ctx, storj.JoinPaths(o.prefix, path))
|
2018-08-16 15:32:28 +01:00
|
|
|
return rr, m, err
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
func (o *prefixedObjStore) Put(ctx context.Context, path storj.Path, data io.Reader, metadata objects.SerializableMeta, expiration time.Time) (meta objects.Meta, err error) {
|
2018-08-16 15:32:28 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-09-09 18:31:26 +01:00
|
|
|
|
|
|
|
if len(path) == 0 {
|
|
|
|
return objects.Meta{}, objects.NoPathError.New("")
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
m, err := o.o.Put(ctx, storj.JoinPaths(o.prefix, path), data, metadata, expiration)
|
2018-08-16 15:32:28 +01:00
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
func (o *prefixedObjStore) Delete(ctx context.Context, path storj.Path) (err error) {
|
2018-08-16 15:32:28 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-09-09 18:31:26 +01:00
|
|
|
|
|
|
|
if len(path) == 0 {
|
|
|
|
return objects.NoPathError.New("")
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
return o.o.Delete(ctx, storj.JoinPaths(o.prefix, path))
|
2018-08-16 15:32:28 +01:00
|
|
|
}
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
func (o *prefixedObjStore) List(ctx context.Context, prefix, startAfter, endBefore storj.Path, recursive bool, limit int, metaFlags uint32) (items []objects.ListItem, more bool, err error) {
|
2018-08-16 15:32:28 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-10-25 21:28:16 +01:00
|
|
|
return o.o.List(ctx, storj.JoinPaths(o.prefix, prefix), startAfter, endBefore, recursive, limit, metaFlags)
|
2018-08-16 15:32:28 +01:00
|
|
|
}
|