mirror of
https://github.com/minio/minio.git
synced 2025-01-24 05:03:16 -05:00
Don't skip rules with ExpiredObjectDeleteMarker (#18256)
This commit is contained in:
parent
f91b257f50
commit
557df666fd
@ -156,7 +156,8 @@ func (lc Lifecycle) HasActiveRules(prefix string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(prefix) > 0 && len(rule.GetPrefix()) > 0 {
|
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) {
|
if !strings.HasPrefix(prefix, rule.GetPrefix()) && !strings.HasPrefix(rule.GetPrefix(), prefix) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -171,15 +172,15 @@ func (lc Lifecycle) HasActiveRules(prefix string) bool {
|
|||||||
if !rule.NoncurrentVersionTransition.IsNull() {
|
if !rule.NoncurrentVersionTransition.IsNull() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if rule.Expiration.IsNull() && rule.Transition.IsNull() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !rule.Expiration.IsDateNull() && rule.Expiration.Date.Before(time.Now().UTC()) {
|
if !rule.Expiration.IsDateNull() && rule.Expiration.Date.Before(time.Now().UTC()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if !rule.Expiration.IsDaysNull() {
|
if !rule.Expiration.IsDaysNull() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if rule.Expiration.DeleteMarker.val {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if !rule.Transition.IsDateNull() && rule.Transition.Date.Before(time.Now().UTC()) {
|
if !rule.Transition.IsDateNull() && rule.Transition.Date.Before(time.Now().UTC()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -575,7 +575,7 @@ func TestHasActiveRules(t *testing.T) {
|
|||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
{ // empty prefix
|
{ // empty prefix
|
||||||
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Expiration><Days>5</Days></Expiration></Rule></LifecycleConfiguration>`,
|
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Filter></Filter><Expiration><Days>5</Days></Expiration></Rule></LifecycleConfiguration>`,
|
||||||
prefix: "foodir/foobject/foo.txt",
|
prefix: "foodir/foobject/foo.txt",
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
@ -600,15 +600,25 @@ func TestHasActiveRules(t *testing.T) {
|
|||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Transition><StorageClass>S3TIER-1</StorageClass></Transition></Rule></LifecycleConfiguration>`,
|
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Filter></Filter><Transition><StorageClass>S3TIER-1</StorageClass></Transition></Rule></LifecycleConfiguration>`,
|
||||||
prefix: "foodir/foobject/foo.txt",
|
prefix: "foodir/foobject/foo.txt",
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><NoncurrentVersionTransition><StorageClass>S3TIER-1</StorageClass></NoncurrentVersionTransition></Rule></LifecycleConfiguration>`,
|
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Filter></Filter><NoncurrentVersionTransition><StorageClass>S3TIER-1</StorageClass></NoncurrentVersionTransition></Rule></LifecycleConfiguration>`,
|
||||||
prefix: "foodir/foobject/foo.txt",
|
prefix: "foodir/foobject/foo.txt",
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Filter></Filter><Expiration><ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker></Expiration></Rule></LifecycleConfiguration>`,
|
||||||
|
prefix: "",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
inputConfig: `<LifecycleConfiguration><Rule><Status>Enabled</Status><Filter></Filter><Expiration><Days>42</Days><ExpiredObjectAllVersions>true</ExpiredObjectAllVersions></Expiration></Rule></LifecycleConfiguration>`,
|
||||||
|
prefix: "",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
@ -618,8 +628,12 @@ func TestHasActiveRules(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Got unexpected error: %v", err)
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user