WIP: Automatically set restore target to / if all backup paths are absolute
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
IamTheFij 2023-10-25 20:01:37 -07:00
parent a2823e09ad
commit 9d1b9c68fd

View File

@ -6,6 +6,7 @@ import (
"io/fs" "io/fs"
"log" "log"
"os" "os"
"path"
"strings" "strings"
) )
@ -405,6 +406,23 @@ func (t BackupFilesTask) RunRestore(cfg TaskConfig) error {
t.RestoreOpts = &RestoreOpts{} //nolint:exhaustruct t.RestoreOpts = &RestoreOpts{} //nolint:exhaustruct
} }
// If all backup paths are absolute and target is empty, use root as the restore target
if t.RestoreOpts.Target == "" {
allAbs := true
for _, backupPath := range t.Paths {
if !path.IsAbs(backupPath) {
allAbs = false
break
}
}
if allAbs {
t.RestoreOpts.Target = "/"
}
}
if t.snapshot == "" { if t.snapshot == "" {
t.snapshot = "latest" t.snapshot = "latest"
} }