From 557df666fde93cee12bdf7af4468925d1318e25d Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Mon, 16 Oct 2023 22:46:46 -0700 Subject: [PATCH] Don't skip rules with ExpiredObjectDeleteMarker (#18256) --- internal/bucket/lifecycle/lifecycle.go | 9 +++++---- internal/bucket/lifecycle/lifecycle_test.go | 22 +++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/internal/bucket/lifecycle/lifecycle.go b/internal/bucket/lifecycle/lifecycle.go index 0d47da36f..ab0ff74b6 100644 --- a/internal/bucket/lifecycle/lifecycle.go +++ b/internal/bucket/lifecycle/lifecycle.go @@ -156,7 +156,8 @@ func (lc Lifecycle) HasActiveRules(prefix string) bool { } if len(prefix) > 0 && len(rule.GetPrefix()) > 0 { - // If recursive, we can skip this rule if it doesn't match the tested prefix. + // we can skip this rule if it doesn't match the tested + // prefix. if !strings.HasPrefix(prefix, rule.GetPrefix()) && !strings.HasPrefix(rule.GetPrefix(), prefix) { continue } @@ -171,15 +172,15 @@ func (lc Lifecycle) HasActiveRules(prefix string) bool { if !rule.NoncurrentVersionTransition.IsNull() { return true } - if rule.Expiration.IsNull() && rule.Transition.IsNull() { - continue - } if !rule.Expiration.IsDateNull() && rule.Expiration.Date.Before(time.Now().UTC()) { return true } if !rule.Expiration.IsDaysNull() { return true } + if rule.Expiration.DeleteMarker.val { + return true + } if !rule.Transition.IsDateNull() && rule.Transition.Date.Before(time.Now().UTC()) { return true } diff --git a/internal/bucket/lifecycle/lifecycle_test.go b/internal/bucket/lifecycle/lifecycle_test.go index e61905e44..9364d772f 100644 --- a/internal/bucket/lifecycle/lifecycle_test.go +++ b/internal/bucket/lifecycle/lifecycle_test.go @@ -575,7 +575,7 @@ func TestHasActiveRules(t *testing.T) { want: true, }, { // empty prefix - inputConfig: `Enabled5`, + inputConfig: `Enabled5`, prefix: "foodir/foobject/foo.txt", want: true, }, @@ -600,15 +600,25 @@ func TestHasActiveRules(t *testing.T) { want: false, }, { - inputConfig: `EnabledS3TIER-1`, + inputConfig: `EnabledS3TIER-1`, prefix: "foodir/foobject/foo.txt", want: true, }, { - inputConfig: `EnabledS3TIER-1`, + inputConfig: `EnabledS3TIER-1`, prefix: "foodir/foobject/foo.txt", want: true, }, + { + inputConfig: `Enabledtrue`, + prefix: "", + want: true, + }, + { + inputConfig: `Enabled42true`, + prefix: "", + want: true, + }, } for i, tc := range testCases { @@ -618,8 +628,12 @@ func TestHasActiveRules(t *testing.T) { if err != nil { t.Fatalf("Got unexpected error: %v", err) } + // To ensure input lifecycle configurations are valid + if err := lc.Validate(); err != nil { + t.Fatalf("Invalid test case: %d %v", i+1, err) + } if got := lc.HasActiveRules(tc.prefix); got != tc.want { - t.Fatalf("Expected result with recursive set to false: `%v`, got: `%v`", tc.want, got) + t.Fatalf("Expected result: `%v`, got: `%v`", tc.want, got) } }) }