2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-08-16 15:32:28 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
package kvmetainfo
|
2018-08-16 15:32:28 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
2018-11-30 15:02:01 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-08-16 15:32:28 +01:00
|
|
|
"storj.io/storj/pkg/ranger"
|
2018-10-25 21:28:16 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/uplink/storage/objects"
|
2018-08-16 15:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type prefixedObjStore struct {
|
2018-11-13 12:21:52 +00:00
|
|
|
store objects.Store
|
2018-08-16 15:32:28 +01:00
|
|
|
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 {
|
2018-11-21 11:17:28 +00:00
|
|
|
return objects.Meta{}, storj.ErrNoPath.New("")
|
2018-09-09 18:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:21:52 +00:00
|
|
|
return o.store.Meta(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) 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 {
|
2018-11-21 11:17:28 +00:00
|
|
|
return nil, objects.Meta{}, storj.ErrNoPath.New("")
|
2018-09-09 18:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:21:52 +00:00
|
|
|
return o.store.Get(ctx, storj.JoinPaths(o.prefix, path))
|
2018-08-16 15:32:28 +01:00
|
|
|
}
|
|
|
|
|
2018-11-30 15:02:01 +00:00
|
|
|
func (o *prefixedObjStore) Put(ctx context.Context, path storj.Path, data io.Reader, metadata pb.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 {
|
2018-11-21 11:17:28 +00:00
|
|
|
return objects.Meta{}, storj.ErrNoPath.New("")
|
2018-09-09 18:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:21:52 +00:00
|
|
|
return o.store.Put(ctx, storj.JoinPaths(o.prefix, path), data, metadata, expiration)
|
2018-08-16 15:32:28 +01:00
|
|
|
}
|
|
|
|
|
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 {
|
2018-11-21 11:17:28 +00:00
|
|
|
return storj.ErrNoPath.New("")
|
2018-09-09 18:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:21:52 +00:00
|
|
|
return o.store.Delete(ctx, storj.JoinPaths(o.prefix, path))
|
2018-08-16 15:32:28 +01:00
|
|
|
}
|
|
|
|
|
2019-09-25 22:30:41 +01:00
|
|
|
func (o *prefixedObjStore) List(ctx context.Context, prefix, startAfter 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-11-13 12:21:52 +00:00
|
|
|
|
2019-09-25 22:30:41 +01:00
|
|
|
return o.store.List(ctx, storj.JoinPaths(o.prefix, prefix), startAfter, recursive, limit, metaFlags)
|
2018-08-16 15:32:28 +01:00
|
|
|
}
|