From 8007d792aad202a377c2ae528210c244b08035ba Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 24 Nov 2026 12:08:21 -0800 Subject: [PATCH] s3_objectlock: scan a literal .versions directory recursively A directory named exactly .versions was listed as flat version files, so a locked object nested below it was missed by the subtree and bucket scans. Co-Authored-By: Claude Opus 5.5 --- weed/s3api/s3_objectlock/object_lock_check.go | 43 ++++--------------- .../s3_objectlock/object_lock_check_test.go | 16 +++++++ 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/weed/s3api/s3_objectlock/object_lock_check.go b/weed/s3api/s3_objectlock/object_lock_check.go index da09b75d82..99c6453c3d 100644 --- a/weed/s3api/s3_objectlock/object_lock_check.go +++ b/weed/s3api/s3_objectlock/object_lock_check.go @@ -146,24 +146,15 @@ func recursivelyCheckLocksWithClient(ctx context.Context, client filer_pb.Seawee } if entry.IsDirectory { - subDir := dir + "/" + entry.Name - if entry.Name == s3_constants.VersionsFolder { - // Check all version files (exact match for .versions folder) - if err := checkVersionsForLocksWithClient(ctx, client, subDir, hasLocks, currentTime); err != nil { - return false, err - } - } else { - // A directory-marker object (key ending in "/") is stored as a - // directory entry and can carry a lock, so check it before recursing. - if EntryHasActiveLock(entry, currentTime) { - *hasLocks = true - glog.V(2).Infof("Found directory marker with active lock: %s/%s", dir, entry.Name) - return true, nil - } - // Recursively check subdirectories - if err := recursivelyCheckLocksWithClient(ctx, client, subDir, hasLocks, currentTime); err != nil { - return false, err - } + // A directory-marker object (key ending in "/") is stored as a + // directory entry and can carry a lock, so check it before recursing. + if EntryHasActiveLock(entry, currentTime) { + *hasLocks = true + glog.V(2).Infof("Found directory marker with active lock: %s/%s", dir, entry.Name) + return true, nil + } + if err := recursivelyCheckLocksWithClient(ctx, client, dir+"/"+entry.Name, hasLocks, currentTime); err != nil { + return false, err } } else { // Check if this object has an active lock @@ -177,22 +168,6 @@ func recursivelyCheckLocksWithClient(ctx context.Context, client filer_pb.Seawee }) } -// checkVersionsForLocksWithClient checks all versions in a .versions directory for active locks -func checkVersionsForLocksWithClient(ctx context.Context, client filer_pb.SeaweedFilerClient, versionsDir string, hasLocks *bool, currentTime time.Time) error { - return paginateEntries(ctx, client, versionsDir, func(entry *filer_pb.Entry) (bool, error) { - if *hasLocks { - return true, nil // Stop iteration - } - - if EntryHasActiveLock(entry, currentTime) { - *hasLocks = true - glog.V(2).Infof("Found version with active lock: %s/%s", versionsDir, entry.Name) - return true, nil // Stop iteration - } - return false, nil // Continue - }) -} - // IsObjectLockEnabled checks if Object Lock is enabled on a bucket entry func IsObjectLockEnabled(entry *filer_pb.Entry) bool { if entry == nil || entry.Extended == nil { diff --git a/weed/s3api/s3_objectlock/object_lock_check_test.go b/weed/s3api/s3_objectlock/object_lock_check_test.go index 8f0894d5ce..718ba3c6bc 100644 --- a/weed/s3api/s3_objectlock/object_lock_check_test.go +++ b/weed/s3api/s3_objectlock/object_lock_check_test.go @@ -91,3 +91,19 @@ func TestHasObjectsWithActiveLocksUnlockedDirectory(t *testing.T) { t.Fatalf("expected no active lock for an ordinary prefix and object") } } + +func TestHasObjectsWithActiveLocksBelowLiteralVersionsDirectory(t *testing.T) { + client := &fakeFilerClient{dirs: map[string][]*filer_pb.Entry{ + "/buckets/b": {{Name: s3_constants.VersionsFolder, IsDirectory: true}}, + "/buckets/b/.versions": {{Name: "nested", IsDirectory: true}}, + "/buckets/b/.versions/nested": {{Name: "held", Extended: map[string][]byte{s3_constants.ExtLegalHoldKey: []byte(s3_constants.LegalHoldOn)}}}, + }} + + has, err := HasObjectsWithActiveLocks(context.Background(), client, "/buckets/b") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if !has { + t.Fatalf("expected the held object below a literal .versions directory to be reported") + } +}