Run hooks in order of severity

This commit is contained in:
Frederik Ring 2021-12-17 20:54:25 +01:00
parent 88c90a206c
commit 1f727f698f

View File

@ -12,6 +12,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"time" "time"
@ -661,6 +662,9 @@ func (s *script) pruneOldBackups() error {
// given levels in the defined ordering. In case executing a hook returns an // given levels in the defined ordering. In case executing a hook returns an
// error, the following hooks will still be run before the function returns. // error, the following hooks will still be run before the function returns.
func (s *script) runHooks(err error, level hookLevel) error { func (s *script) runHooks(err error, level hookLevel) error {
sort.SliceStable(s.hooks, func(i, j int) bool {
return s.hooks[i].level < s.hooks[j].level
})
var actionErrors []error var actionErrors []error
for _, hook := range s.hooks { for _, hook := range s.hooks {
if hook.level > level { if hook.level > level {