From 1f727f698fe49b4b5bee3fbd03955264ef1ed1e5 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 17 Dec 2021 20:54:25 +0100 Subject: [PATCH] Run hooks in order of severity --- cmd/backup/main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/backup/main.go b/cmd/backup/main.go index 1e5350e..ea255fd 100644 --- a/cmd/backup/main.go +++ b/cmd/backup/main.go @@ -12,6 +12,7 @@ import ( "os" "path" "path/filepath" + "sort" "strings" "time" @@ -661,6 +662,9 @@ func (s *script) pruneOldBackups() error { // 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. 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 for _, hook := range s.hooks { if hook.level > level {