aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-02-01 10:49:17 -0800
committerChris Lu <chris.lu@gmail.com>2021-02-01 10:49:17 -0800
commit609daaf3878927f86a4d4a59eb7f8d9786232a5c (patch)
tree2ceea4b0cebd87c7546c637f5486882859be4332
parent9c56b46886491c62054368206c0ca3e4e8014a17 (diff)
downloadseaweedfs-609daaf3878927f86a4d4a59eb7f8d9786232a5c.tar.xz
seaweedfs-609daaf3878927f86a4d4a59eb7f8d9786232a5c.zip
s3: DeleteMultipleObjectsHandler clean up leftover empty folders
fix https://github.com/chrislusf/seaweedfs/issues/1772
-rw-r--r--weed/s3api/s3api_object_handlers.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go
index 1c0b290c9..ffe46aa85 100644
--- a/weed/s3api/s3api_object_handlers.go
+++ b/weed/s3api/s3api_object_handlers.go
@@ -206,18 +206,8 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
}
// purge empty folders, only checking folders with deletions
- var allDirs []string
- for dir, _ := range directoriesWithDeletion {
- allDirs = append(allDirs, dir)
- }
- sort.Slice(allDirs, func(i, j int) bool {
- return len(allDirs[i]) > len(allDirs[j])
- })
- for _, dir := range allDirs {
- parentDir, dirName := util.FullPath(dir).DirAndName()
- if err := doDeleteEntry(client, parentDir, dirName, false, false); err != nil {
- glog.V(4).Infof("directory %s has %d deletion but still not empty: %v", dir, directoriesWithDeletion[dir], err)
- }
+ for len(directoriesWithDeletion) > 0 {
+ directoriesWithDeletion = doDeleteEmptyDirectories(client, directoriesWithDeletion)
}
return nil
@@ -233,6 +223,26 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
}
+func doDeleteEmptyDirectories(client filer_pb.SeaweedFilerClient, directoriesWithDeletion map[string]int) (newDirectoriesWithDeletion map[string]int){
+ var allDirs []string
+ for dir, _ := range directoriesWithDeletion {
+ allDirs = append(allDirs, dir)
+ }
+ sort.Slice(allDirs, func(i, j int) bool {
+ return len(allDirs[i]) > len(allDirs[j])
+ })
+ newDirectoriesWithDeletion = make(map[string]int)
+ for _, dir := range allDirs {
+ parentDir, dirName := util.FullPath(dir).DirAndName()
+ if err := doDeleteEntry(client, parentDir, dirName, false, false); err != nil {
+ glog.V(4).Infof("directory %s has %d deletion but still not empty: %v", dir, directoriesWithDeletion[dir], err)
+ } else {
+ newDirectoriesWithDeletion[parentDir]++
+ }
+ }
+ return
+}
+
var passThroughHeaders = []string{
"response-cache-control",
"response-content-disposition",