diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-10-25 11:21:33 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-10-25 11:21:33 -0700 |
| commit | 147d4d23b64173ac8cc48dba10e00fffa2ec5cbe (patch) | |
| tree | 564492108cfcd14465ece7e19c8a2581d7ecedad /weed/command/filer_copy.go | |
| parent | 91fd311f7a7e84217f4dde536de50e31948b669b (diff) | |
| download | seaweedfs-147d4d23b64173ac8cc48dba10e00fffa2ec5cbe.tar.xz seaweedfs-147d4d23b64173ac8cc48dba10e00fffa2ec5cbe.zip | |
filer.copy: automatically use the right bucket
Diffstat (limited to 'weed/command/filer_copy.go')
| -rw-r--r-- | weed/command/filer_copy.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/weed/command/filer_copy.go b/weed/command/filer_copy.go index 88148acc5..610a3e510 100644 --- a/weed/command/filer_copy.go +++ b/weed/command/filer_copy.go @@ -111,11 +111,23 @@ func runCopy(cmd *Command, args []string) bool { filerGrpcAddress := fmt.Sprintf("%s:%d", filerUrl.Hostname(), filerGrpcPort) copy.grpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client") - masters, collection, replication, maxMB, cipher, err := readFilerConfiguration(copy.grpcDialOption, filerGrpcAddress) + masters, collection, replication, dirBuckets, maxMB, cipher, err := readFilerConfiguration(copy.grpcDialOption, filerGrpcAddress) if err != nil { fmt.Printf("read from filer %s: %v\n", filerGrpcAddress, err) return false } + if strings.HasPrefix(urlPath, dirBuckets) { + restPath := urlPath[len(dirBuckets)+1:] + if strings.Index(restPath, "/") > 0 { + expectedBucket := restPath[:strings.Index(restPath, "/")] + if *copy.collection == "" { + *copy.collection = expectedBucket + } else { + fmt.Printf("destination %s uses collection \"%s\": unexpected collection \"%v\"\n", urlPath, expectedBucket, *copy.collection) + return true + } + } + } if *copy.collection == "" { *copy.collection = collection } @@ -170,13 +182,14 @@ func runCopy(cmd *Command, args []string) bool { return true } -func readFilerConfiguration(grpcDialOption grpc.DialOption, filerGrpcAddress string) (masters []string, collection, replication string, maxMB uint32, cipher bool, err error) { +func readFilerConfiguration(grpcDialOption grpc.DialOption, filerGrpcAddress string) (masters []string, collection, replication string, dirBuckets string, maxMB uint32, cipher bool, err error) { err = pb.WithGrpcFilerClient(filerGrpcAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{}) if err != nil { return fmt.Errorf("get filer %s configuration: %v", filerGrpcAddress, err) } masters, collection, replication, maxMB = resp.Masters, resp.Collection, resp.Replication, resp.MaxMb + dirBuckets = resp.DirBuckets cipher = resp.Cipher return nil }) |
