Harden backup and restore operations

This commit is contained in:
Mikei386
2026-07-13 19:47:43 +02:00
parent 6cbf170d65
commit bbf063c157
26 changed files with 914 additions and 184 deletions
+14 -2
View File
@@ -7,7 +7,10 @@ import (
"time"
)
type Expression struct{ fields [5]field }
type Expression struct {
fields [5]field
restricted [5]bool
}
type field map[int]bool
var bounds = [5][2]int{{0, 59}, {0, 23}, {1, 31}, {1, 12}, {0, 6}}
@@ -24,6 +27,7 @@ func Parse(spec string) (Expression, error) {
return Expression{}, fmt.Errorf("cron field %d: %w", i+1, err)
}
expression.fields[i] = parsed
expression.restricted[i] = part != "*"
}
return expression, nil
}
@@ -76,11 +80,19 @@ func parseField(value string, min, max int) (field, error) {
func (e Expression) Matches(t time.Time) bool {
values := [5]int{t.Minute(), t.Hour(), t.Day(), int(t.Month()), int(t.Weekday())}
for i, value := range values {
if i == 2 || i == 4 {
continue
}
if !e.fields[i][value] {
return false
}
}
return true
dayOfMonth := e.fields[2][values[2]]
dayOfWeek := e.fields[4][values[4]]
if e.restricted[2] && e.restricted[4] {
return dayOfMonth || dayOfWeek
}
return dayOfMonth && dayOfWeek
}
func (e Expression) Next(after time.Time) time.Time {