Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

s3: DeleteMultipleObjectsHandler clean up leftover empty folders

Chris Lu609daaf38789
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go
index 1c0b290c90..ffe46aa85f 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",