-
Notifications
You must be signed in to change notification settings - Fork 2
/
bucket_core.go
71 lines (53 loc) · 2.26 KB
/
bucket_core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package crabfs
import (
"context"
"io"
"path"
"time"
crabfsCrypto "github.com/runletapp/crabfs/crypto"
"github.com/runletapp/crabfs/interfaces"
pb "github.com/runletapp/crabfs/protos"
)
var _ interfaces.Bucket = &bucketCoreImpl{}
type bucketCoreImpl struct {
privateKey crabfsCrypto.PrivKey
bucket string
fs interfaces.Core
root string
}
// BucketCoreNew creates a new bucket core io
func BucketCoreNew(fs interfaces.Core, privateKey crabfsCrypto.PrivKey, bucket string, root string) interfaces.Bucket {
return &bucketCoreImpl{
privateKey: privateKey,
bucket: bucket,
root: root,
fs: fs,
}
}
func (b *bucketCoreImpl) Get(ctx context.Context, filename string) (interfaces.Fetcher, error) {
return b.fs.Get(ctx, b.privateKey, b.bucket, path.Join(b.root, filename))
}
func (b *bucketCoreImpl) Put(ctx context.Context, filename string, file io.Reader, mtime time.Time) error {
return b.fs.Put(ctx, b.privateKey, b.bucket, path.Join(b.root, filename), file, mtime)
}
func (b *bucketCoreImpl) PutAndLock(ctx context.Context, filename string, file io.Reader, mtime time.Time) (*pb.LockToken, error) {
return b.fs.PutAndLock(ctx, b.privateKey, b.bucket, path.Join(b.root, filename), file, mtime)
}
func (b *bucketCoreImpl) PutWithCacheTTL(ctx context.Context, filename string, file io.Reader, mtime time.Time, ttl uint64) error {
return b.fs.PutWithCacheTTL(ctx, b.privateKey, b.bucket, path.Join(b.root, filename), file, mtime, ttl)
}
func (b *bucketCoreImpl) Remove(ctx context.Context, filename string) error {
return b.fs.Remove(ctx, b.privateKey, b.bucket, path.Join(b.root, filename))
}
func (b *bucketCoreImpl) Chroot(dir string) interfaces.Bucket {
return BucketCoreNew(b.fs, b.privateKey, b.bucket, path.Join(b.root, dir))
}
func (b *bucketCoreImpl) Lock(ctx context.Context, filename string) (*pb.LockToken, error) {
return b.fs.Lock(ctx, b.privateKey, b.bucket, path.Join(b.root, filename))
}
func (b *bucketCoreImpl) Unlock(ctx context.Context, filename string, token *pb.LockToken) error {
return b.fs.Unlock(ctx, b.privateKey, b.bucket, path.Join(b.root, filename), token)
}
func (b *bucketCoreImpl) IsLocked(ctx context.Context, filename string) (bool, error) {
return b.fs.IsLocked(ctx, b.privateKey.GetPublic(), b.bucket, path.Join(b.root, filename))
}