refactoring filer rm

This commit is contained in:
Chris Lu 2018-09-03 13:16:26 -07:00
parent 03f852c799
commit 2ed6d8cca6
2 changed files with 27 additions and 15 deletions

View file

@ -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
})
}

View file

@ -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