remote storage location changed to struct

This commit is contained in:
Chris Lu
2021-07-29 02:08:55 -07:00
parent c090d6bb25
commit 899963ac20
9 changed files with 320 additions and 216 deletions

View File

@@ -8,22 +8,21 @@ import (
"sync"
)
type RemoteStorageLocation string
func (remote RemoteStorageLocation) NameBucketPath() (storageName, bucket, remotePath string) {
func ParseLocation(remote string) (loc *filer_pb.RemoteStorageLocation) {
loc = &filer_pb.RemoteStorageLocation{}
if strings.HasSuffix(string(remote), "/") {
remote = remote[:len(remote)-1]
}
parts := strings.SplitN(string(remote), "/", 3)
if len(parts) >= 1 {
storageName = parts[0]
loc.Name = parts[0]
}
if len(parts) >= 2 {
bucket = parts[1]
loc.Bucket = parts[1]
}
remotePath = string(remote[len(storageName)+1+len(bucket):])
if remotePath == "" {
remotePath = "/"
loc.Path = string(remote[len(loc.Name)+1+len(loc.Bucket):])
if loc.Path == "" {
loc.Path = "/"
}
return
}
@@ -31,8 +30,8 @@ func (remote RemoteStorageLocation) NameBucketPath() (storageName, bucket, remot
type VisitFunc func(dir string, name string, isDirectory bool, remoteEntry *filer_pb.RemoteEntry) error
type RemoteStorageClient interface {
Traverse(remote RemoteStorageLocation, visitFn VisitFunc) error
ReadFile(bucket, key string, offset int64, size int64, writeFn func(w io.Writer) error) error
Traverse(loc *filer_pb.RemoteStorageLocation, visitFn VisitFunc) error
ReadFile(loc *filer_pb.RemoteStorageLocation, offset int64, size int64, writeFn func(w io.Writer) error) error
}
type RemoteStorageClientMaker interface {

View File

@@ -10,6 +10,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/remote_storage"
"github.com/chrislusf/seaweedfs/weed/util"
"io"
)
func init() {
@@ -44,13 +45,12 @@ type s3RemoteStorageClient struct {
conn s3iface.S3API
}
func (s s3RemoteStorageClient) Traverse(remote remote_storage.RemoteStorageLocation, visitFn remote_storage.VisitFunc) (err error) {
func (s s3RemoteStorageClient) Traverse(remote *filer_pb.RemoteStorageLocation, visitFn remote_storage.VisitFunc) (err error) {
_, bucket, pathKey := remote.NameBucketPath()
pathKey = pathKey[1:]
pathKey := remote.Path[1:]
listInput := &s3.ListObjectsV2Input{
Bucket: aws.String(bucket),
Bucket: aws.String(remote.Bucket),
ContinuationToken: nil,
Delimiter: nil, // not aws.String("/"), iterate through all entries
EncodingType: nil,
@@ -91,3 +91,6 @@ func (s s3RemoteStorageClient) Traverse(remote remote_storage.RemoteStorageLocat
}
return
}
func (s s3RemoteStorageClient) ReadFile(loc *filer_pb.RemoteStorageLocation, offset int64, size int64, writeFn func(w io.Writer) error) error {
return nil
}