mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
83be02c814
commit
8007d792aa
2 files changed
+25
-34
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user