diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-01-28 14:28:40 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-01-28 14:28:40 -0800 |
| commit | c2bf1a88ac1af1cc573f21c6d98c191be7f59281 (patch) | |
| tree | 80841da9d898809d8f71e32c83ccaad58c1eadc4 | |
| parent | e9d820192587e6ae01d7183f99b898953f192cf7 (diff) | |
| download | seaweedfs-c2bf1a88ac1af1cc573f21c6d98c191be7f59281.tar.xz seaweedfs-c2bf1a88ac1af1cc573f21c6d98c191be7f59281.zip | |
delete from the deepest directory first when checking empty folders
| -rw-r--r-- | weed/s3api/s3api_object_handlers.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index e8c1b59d7..ab79d1976 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -8,6 +8,7 @@ import ( "io" "io/ioutil" "net/http" + "sort" "strings" "github.com/chrislusf/seaweedfs/weed/s3api/s3err" @@ -204,11 +205,20 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h } } + + // purge empty folders, only checking folders with deletions - for dir, deletionCount := range directoriesWithDeletion { + 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, deletionCount, err) + glog.V(4).Infof("directory %s has %d deletion but still not empty: %v", dir, directoriesWithDeletion[dir], err) } } |
