Files
kopia/snapshot/policy/optional.go
Jarek Kowalski 90df511609 fix(snapshots): treat empty retention policy as retaining ALL, not NONE (#1733)
This is a safety measure which addresses P0 improvement for #1732.

Given that retention policies that retain nothing make no sense, this
is not considered a breaking change.
2022-02-07 11:40:27 -08:00

34 lines
711 B
Go

package policy
// OptionalBool provides convenience methods for manipulating optional booleans.
type OptionalBool bool
// OrDefault returns the value of the boolean or provided default if it's nil.
func (b *OptionalBool) OrDefault(def bool) bool {
if b == nil {
return def
}
return bool(*b)
}
func newOptionalBool(b OptionalBool) *OptionalBool {
return &b
}
// OptionalInt provides convenience methods for manipulating optional integers.
type OptionalInt int
// OrDefault returns the value of the integer or provided default if it's nil.
func (b *OptionalInt) OrDefault(def int) int {
if b == nil {
return def
}
return int(*b)
}
func newOptionalInt(b OptionalInt) *OptionalInt {
return &b
}