aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2025-11-05 14:12:20 -0800
committerchrislu <chris.lu@gmail.com>2025-11-05 14:12:20 -0800
commit55ee4513e77d9b0aefb67bb86bb75519ee29aad3 (patch)
treea196efe32bbdfac3b569ed33daeb65f27ef29f97
parentd8bef68752a7548d280f09cb244762943e4db6f7 (diff)
downloadseaweedfs-55ee4513e77d9b0aefb67bb86bb75519ee29aad3.tar.xz
seaweedfs-55ee4513e77d9b0aefb67bb86bb75519ee29aad3.zip
cleaner
-rw-r--r--weed/filer/filer.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/weed/filer/filer.go b/weed/filer/filer.go
index 75c50871e..69b57d749 100644
--- a/weed/filer/filer.go
+++ b/weed/filer/filer.go
@@ -420,13 +420,29 @@ func (f *Filer) doListDirectoryEntries(ctx context.Context, p util.FullPath, sta
if !hasValidEntries && p != "/" && startFileName == "" {
// Do a quick check to see if directory is truly empty now
if isEmpty, checkErr := f.IsDirectoryEmpty(ctx, p); checkErr == nil && isEmpty {
- glog.V(2).InfofCtx(ctx, "doListDirectoryEntries: deleting empty directory %s after expiring all entries", p)
- parentDir, _ := p.DirAndName()
- if dirEntry, findErr := f.FindEntry(ctx, p); findErr == nil {
- // Delete the now-empty directory
- if delErr := f.doDeleteEntryMetaAndData(ctx, dirEntry, false, false, nil); delErr == nil {
- // Recursively try to delete parent directories if they become empty
- f.DeleteEmptyParentDirectories(ctx, util.FullPath(parentDir), "")
+ // Safety: Always limit recursive deletion scope
+ // For S3 buckets, DirBucketsPath is always set (e.g., "/buckets")
+ // Don't delete bucket directories or the buckets path itself
+ stopAtPath := util.FullPath(f.DirBucketsPath)
+
+ // Check if this is a bucket-level directory that should never be deleted
+ baseDepth := strings.Count(f.DirBucketsPath, "/")
+ dirDepth := strings.Count(string(p), "/")
+
+ // If directory is at bucket level (e.g., /buckets/mybucket) or above, don't delete
+ if dirDepth <= baseDepth+1 {
+ glog.V(2).InfofCtx(ctx, "doListDirectoryEntries: skipping deletion of bucket-level directory %s", p)
+ } else {
+ // Safe to delete subdirectories within buckets
+ glog.V(2).InfofCtx(ctx, "doListDirectoryEntries: deleting empty directory %s after expiring all entries", p)
+ parentDir, _ := p.DirAndName()
+ if dirEntry, findErr := f.FindEntry(ctx, p); findErr == nil {
+ // Delete the now-empty directory
+ if delErr := f.doDeleteEntryMetaAndData(ctx, dirEntry, false, false, nil); delErr == nil {
+ // Recursively try to delete parent directories if they become empty
+ // Stop at the buckets path to prevent deleting bucket directories
+ f.DeleteEmptyParentDirectories(ctx, util.FullPath(parentDir), stopAtPath)
+ }
}
}
}