Skip to content

Commit

Permalink
fix(cron): crash when errors are encountered during a backup (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotboris authored Oct 17, 2024
1 parent 6424c64 commit 41e4e4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion internal/cron.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package internal

import (
"errors"
"fmt"
)

func RunCron() error {
c := GetConfig()
var errs []error
for name, l := range c.Locations {
l.name = name
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
}
6 changes: 5 additions & 1 deletion internal/location.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -446,7 +447,10 @@ func (l Location) RunCron() error {
now := time.Now()
if now.After(next) {
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 {
if !flags.CRON_LEAN {
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
Expand Down

0 comments on commit 41e4e4a

Please sign in to comment.