mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
merge object lifecycle checks into usage crawler (#9579)
This commit is contained in:
24
pkg/bucket/lifecycle/action_string.go
Normal file
24
pkg/bucket/lifecycle/action_string.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Code generated by "stringer -type Action lifecycle.go"; DO NOT EDIT.
|
||||
|
||||
package lifecycle
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[NoneAction-0]
|
||||
_ = x[DeleteAction-1]
|
||||
}
|
||||
|
||||
const _Action_name = "NoneActionDeleteAction"
|
||||
|
||||
var _Action_index = [...]uint8{0, 10, 22}
|
||||
|
||||
func (i Action) String() string {
|
||||
if i < 0 || i >= Action(len(_Action_index)-1) {
|
||||
return "Action(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Action_name[_Action_index[i]:_Action_index[i+1]]
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (e Expiration) IsDaysNull() bool {
|
||||
|
||||
// IsDateNull returns true if date field is null
|
||||
func (e Expiration) IsDateNull() bool {
|
||||
return e.Date == ExpirationDate{time.Time{}}
|
||||
return e.Date.Time.IsZero()
|
||||
}
|
||||
|
||||
// IsNull returns true if both date and days fields are null
|
||||
|
||||
@@ -33,6 +33,8 @@ var (
|
||||
// actions that will be implemented later.
|
||||
type Action int
|
||||
|
||||
//go:generate stringer -type Action $GOFILE
|
||||
|
||||
const (
|
||||
// NoneAction means no action required after evaluting lifecycle rules
|
||||
NoneAction Action = iota
|
||||
@@ -46,9 +48,44 @@ type Lifecycle struct {
|
||||
Rules []Rule `xml:"Rule"`
|
||||
}
|
||||
|
||||
// IsEmpty - returns whether policy is empty or not.
|
||||
func (lc Lifecycle) IsEmpty() bool {
|
||||
return len(lc.Rules) == 0
|
||||
// HasActiveRules - returns whether policy has active rules for.
|
||||
// Optionally a prefix can be supplied.
|
||||
// If recursive is specified the function will also return true if any level below the
|
||||
// prefix has active rules. If no prefix is specified recursive is effectively true.
|
||||
func (lc Lifecycle) HasActiveRules(prefix string, recursive bool) bool {
|
||||
if len(lc.Rules) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, rule := range lc.Rules {
|
||||
if rule.Status == Disabled {
|
||||
continue
|
||||
}
|
||||
if len(prefix) > 0 && len(rule.Filter.Prefix) > 0 {
|
||||
// incoming prefix must be in rule prefix
|
||||
if !recursive && !strings.HasPrefix(prefix, rule.Filter.Prefix) {
|
||||
continue
|
||||
}
|
||||
// If recursive, we can skip this rule if it doesn't match the tested prefix.
|
||||
if recursive && !strings.HasPrefix(rule.Filter.Prefix, prefix) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if rule.NoncurrentVersionExpiration.NoncurrentDays > 0 {
|
||||
return true
|
||||
}
|
||||
if rule.NoncurrentVersionTransition.NoncurrentDays > 0 {
|
||||
return true
|
||||
}
|
||||
if rule.Expiration.IsNull() {
|
||||
continue
|
||||
}
|
||||
if !rule.Expiration.IsDateNull() && rule.Expiration.Date.After(time.Now()) {
|
||||
continue
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ParseLifecycleConfig - parses data in given reader to Lifecycle.
|
||||
|
||||
Reference in New Issue
Block a user