Browse Source

refactoring filer rm

pull/729/head
Chris Lu 6 years ago
parent
commit
2ed6d8cca6
  1. 26
      weed/s3api/filer_util.go
  2. 16
      weed/s3api/s3api_bucket_handlers.go

26
weed/s3api/filer_util.go

@ -38,7 +38,7 @@ func (s3a *S3ApiServer) mkdir(parentDirectoryPath string, dirName string) error
func (s3a *S3ApiServer) list(parentDirectoryPath string) (entries []*filer_pb.Entry, err error) {
s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
err = s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.ListEntriesRequest{
Directory: s3a.option.BucketsPath,
@ -58,3 +58,27 @@ func (s3a *S3ApiServer) list(parentDirectoryPath string) (entries []*filer_pb.En
return
}
func (s3a *S3ApiServer) rm(parentDirectoryPath string, entryName string, isDirectory, isDeleteData, isRecursive bool) error {
return s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
ctx := context.Background()
request := &filer_pb.DeleteEntryRequest{
Directory: parentDirectoryPath,
Name: entryName,
IsDirectory: isDirectory,
IsDeleteData: isDeleteData,
IsRecursive: isRecursive,
}
glog.V(1).Infof("delete entry %v/%v: %v", parentDirectoryPath, entryName, request)
if _, err := client.DeleteEntry(ctx, request); err != nil {
return fmt.Errorf("delete entry %s/%s: %v", parentDirectoryPath, entryName, err)
}
return nil
})
}

16
weed/s3api/s3api_bucket_handlers.go

@ -86,23 +86,11 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
return fmt.Errorf("delete collection %s: %v", bucket, err)
}
// delete bucket metadata
request := &filer_pb.DeleteEntryRequest{
Directory: s3a.option.BucketsPath,
Name: bucket,
IsDirectory: true,
IsDeleteData: false,
IsRecursive: true,
}
glog.V(1).Infof("delete bucket: %v", request)
if _, err := client.DeleteEntry(ctx, request); err != nil {
return fmt.Errorf("delete bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)
}
return nil
})
err = s3a.rm(s3a.option.BucketsPath, bucket, true, false, true)
if err != nil {
writeErrorResponse(w, ErrInternalError, r.URL)
return

Loading…
Cancel
Save