filer: run the lock pre-pass for ancestors of the buckets dir

A recursive delete rooted at the buckets dir (or an ancestor of it when
nested) reaches each bucket only mid-walk, where an unmarked bucket on a
drop-capable store loses its children to an unchecked
DeleteFolderChildren. mayDescendantsHoldLocks now also answers true when
the subtree contains the buckets dir rather than sitting inside it, so
the pre-pass walks those buckets before the first drop can run.
This commit is contained in:
user.email committed 2026-10-23 18:56:57 -07:00
1 parent de470c66fb
commit 75967b355c
2 files changed
+28 -1

No files matched your search

+5 -1
View File
@@ -205,7 +205,11 @@ func (f *Filer) mayDescendantsHoldLocks(ctx context.Context, p util.FullPath, en
}
rel := strings.TrimPrefix(string(p), f.DirBucketsPath+"/")
if rel == string(p) {
return false
// The subtree can also hold locks by containing the buckets dir
// itself: deleting it or an ancestor drops each bucket's children
// unseen mid-walk.
dir := strings.TrimSuffix(string(p), "/")
return dir == f.DirBucketsPath || strings.HasPrefix(f.DirBucketsPath, dir+"/")
}
bucket, _, _ := strings.Cut(rel, "/")
if bucket == "" {
+23
View File
@@ -359,6 +359,29 @@ func TestDeleteUnmarkedBucketNonRecursiveRefusesLockedObject(t *testing.T) {
require.NotNil(t, store.getEntry("/buckets/b/held.bin"), "a non-recursive unmarked bucket drop must not swallow the locked object")
}
// A recursive delete rooted at the buckets dir reaches each bucket only
// mid-walk, so the pre-pass has to know the subtree holds buckets whose
// children the store would drop unseen.
func TestDeleteBucketsRootRecursiveRefusesLockedObject(t *testing.T) {
store := newStubFilerStore()
f := newTestFiler(t, store, NewFilerRemoteStorage())
f.DirBucketsPath = "/buckets"
f.Store = NewFilerStoreWrapper(&bucketDropStore{store})
ctx := context.Background()
require.NoError(t, f.CreateEntry(ctx, &Entry{FullPath: "/buckets", Attr: Attr{Mode: os.ModeDir | 0755}}, nil, false, false, nil, true, 255))
require.NoError(t, f.CreateEntry(ctx, &Entry{FullPath: "/buckets/b", Attr: Attr{Mode: os.ModeDir | 0755}}, nil, false, false, nil, true, 255))
require.NoError(t, f.CreateEntry(ctx, &Entry{
FullPath: "/buckets/b/held.bin",
Attr: Attr{Mode: 0644},
Extended: map[string][]byte{s3_constants.ExtLegalHoldKey: []byte("ON")},
}, nil, false, false, nil, true, 255))
err := f.DeleteEntryMetaAndData(ctx, "/buckets", true, true, true, false, nil, 0)
require.ErrorIs(t, err, ErrEntryLocked)
require.NotNil(t, store.getEntry("/buckets/b/held.bin"), "an unseen bucket drop must not swallow the locked object")
}
// An expired retention no longer locks: the delete proceeds normally.
func TestDeleteEntryAllowsExpiredRetention(t *testing.T) {
store := newStubFilerStore()