Browse Source

cleaner

pull/7426/head
chrislu 4 weeks ago
parent
commit
55ee4513e7
  1. 30
      weed/filer/filer.go

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

Loading…
Cancel
Save