From b8b44c879f5e9e9bea6ff2600cbbb056dfc37416 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 10 Feb 2021 17:51:34 +0100 Subject: [PATCH] lifecycle: Remove a single delete marker with noncurrent expiry rule (#11444) NoncurrentVersionExpiry can remove single delete markers according to S3 spec: ``` The NoncurrentVersionExpiration action in the same Lifecycle configuration removes noncurrent objects 30 days after they become noncurrent. Thus, in this example, all object versions are permanently removed 90 days after object creation. You will have expired object delete markers, but Amazon S3 detects and removes the expired object delete markers for you. ``` --- pkg/bucket/lifecycle/lifecycle.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/bucket/lifecycle/lifecycle.go b/pkg/bucket/lifecycle/lifecycle.go index eef08bd21..9495ea739 100644 --- a/pkg/bucket/lifecycle/lifecycle.go +++ b/pkg/bucket/lifecycle/lifecycle.go @@ -245,7 +245,19 @@ func (lc Lifecycle) ComputeAction(obj ObjectOpts) Action { return DeleteVersionAction } } + + if obj.VersionID != "" && obj.DeleteMarker && obj.NumVersions == 1 { + // From https: //docs.aws.amazon.com/AmazonS3/latest/dev/lifecycle-configuration-examples.html : + // The NoncurrentVersionExpiration action in the same Lifecycle configuration removes noncurrent objects X days + // after they become noncurrent. Thus, in this example, all object versions are permanently removed X days after + // object creation. You will have expired object delete markers, but Amazon S3 detects and removes the expired + // object delete markers for you. + if time.Now().After(ExpectedExpiryTime(obj.ModTime, int(rule.NoncurrentVersionExpiration.NoncurrentDays))) { + return DeleteVersionAction + } + } } + if !rule.NoncurrentVersionTransition.IsDaysNull() { if obj.VersionID != "" && !obj.IsLatest && !obj.SuccessorModTime.IsZero() && obj.TransitionStatus != TransitionComplete { // Non current versions should be deleted if their age exceeds non current days configuration