From 4cf80f96ad9d57bad5fac65f035993ce824328b0 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Sun, 5 Jul 2020 17:08:42 +0100 Subject: [PATCH] fix: lifecycle XML parsing errors with Versioning (#9974) --- cmd/data-crawler.go | 1 + pkg/bucket/lifecycle/expiration.go | 21 ++++----------------- pkg/bucket/lifecycle/lifecycle.go | 2 -- pkg/bucket/lifecycle/noncurrentversion.go | 9 +++++---- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/cmd/data-crawler.go b/cmd/data-crawler.go index 723b0fb2e..af35b5ab0 100644 --- a/cmd/data-crawler.go +++ b/cmd/data-crawler.go @@ -582,6 +582,7 @@ func (i *crawlItem) applyActions(ctx context.Context, o ObjectLayer, meta action VersionID: obj.VersionID, DeleteMarker: obj.DeleteMarker, IsLatest: obj.IsLatest, + NumVersions: meta.numVersions, }) if i.debug { logger.Info(color.Green("applyActions:")+" lifecycle: Secondary scan: %v", action) diff --git a/pkg/bucket/lifecycle/expiration.go b/pkg/bucket/lifecycle/expiration.go index f220e3fa8..7dbd472e4 100644 --- a/pkg/bucket/lifecycle/expiration.go +++ b/pkg/bucket/lifecycle/expiration.go @@ -108,26 +108,13 @@ type Expiration struct { DeleteMarker ExpireDeleteMarker `xml:"ExpiredObjectDeleteMarker,omitempty"` } -// UnmarshalXML parses delete marker and validates if it is set. -func (b *ExpireDeleteMarker) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error { - if !*b { - return nil - } - var deleteMarker bool - err := d.DecodeElement(&deleteMarker, &startElement) - if err != nil { - return err - } - *b = ExpireDeleteMarker(deleteMarker) - return nil -} - // MarshalXML encodes delete marker boolean into an XML form. -func (b *ExpireDeleteMarker) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error { - if !*b { +func (b ExpireDeleteMarker) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error { + if !b { return nil } - return e.EncodeElement(*b, startElement) + type expireDeleteMarkerWrapper ExpireDeleteMarker + return e.EncodeElement(expireDeleteMarkerWrapper(b), startElement) } // Validate - validates the "Expiration" element diff --git a/pkg/bucket/lifecycle/lifecycle.go b/pkg/bucket/lifecycle/lifecycle.go index 613689d45..8b596ea60 100644 --- a/pkg/bucket/lifecycle/lifecycle.go +++ b/pkg/bucket/lifecycle/lifecycle.go @@ -204,9 +204,7 @@ func (lc Lifecycle) ComputeAction(obj ObjectOpts) Action { if time.Now().After(expectedExpiryTime(obj.ModTime, rule.NoncurrentVersionExpiration.NoncurrentDays)) { return DeleteVersionAction } - return NoneAction } - return NoneAction } // All other expiration only applies to latest versions diff --git a/pkg/bucket/lifecycle/noncurrentversion.go b/pkg/bucket/lifecycle/noncurrentversion.go index a1bfa28df..73af35b1f 100644 --- a/pkg/bucket/lifecycle/noncurrentversion.go +++ b/pkg/bucket/lifecycle/noncurrentversion.go @@ -36,12 +36,13 @@ var ( errNoncurrentVersionTransitionUnsupported = Errorf("Specifying is not supported") ) -// MarshalXML if non-current days not set returns empty tags -func (n *NoncurrentVersionExpiration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - if n.NoncurrentDays == ExpirationDays(0) { +// MarshalXML if non-current days not set to non zero value +func (n NoncurrentVersionExpiration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + if n.IsDaysNull() { return nil } - return e.EncodeElement(&n, start) + type noncurrentVersionExpirationWrapper NoncurrentVersionExpiration + return e.EncodeElement(noncurrentVersionExpirationWrapper(n), start) } // IsDaysNull returns true if days field is null