fix(cron): crash when errors are encountered during a backup (#403)

pull/404/head
Boris Bera 1 month ago committed by GitHub
parent 6424c64304
commit 41e4e4a5f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,12 +1,22 @@
package internal package internal
import (
"errors"
"fmt"
)
func RunCron() error { func RunCron() error {
c := GetConfig() c := GetConfig()
var errs []error
for name, l := range c.Locations { for name, l := range c.Locations {
l.name = name l.name = name
if err := l.RunCron(); err != nil { if err := l.RunCron(); err != nil {
return err errs = append(errs, err)
} }
} }
if len(errs) > 0 {
return fmt.Errorf("Encountered errors during cron process:\n%w", errors.Join(errs...))
}
return nil return nil
} }

@ -1,6 +1,7 @@
package internal package internal
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -446,7 +447,10 @@ func (l Location) RunCron() error {
now := time.Now() now := time.Now()
if now.After(next) { if now.After(next) {
lock.SetCron(l.name, now.Unix()) lock.SetCron(l.name, now.Unix())
l.Backup(true, "") errs := l.Backup(true, "")
if len(errs) > 0 {
return fmt.Errorf("Failed to backup location \"%s\":\n%w", l.name, errors.Join(errs...))
}
} else { } else {
if !flags.CRON_LEAN { if !flags.CRON_LEAN {
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name) colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)

Loading…
Cancel
Save