From bb29a9861401faec6d74b69cf2473e190282acb5 Mon Sep 17 00:00:00 2001 From: Duru Can Celasun Date: Sat, 22 Mar 2025 18:12:36 +0000 Subject: [PATCH] feat: Run PreValidate hooks for check cmd (#437) PreValidate can be used to mount remote directories (e.g. via NFS) so they must executed first before running any restic commands. This was done for the backup command in 13aa560, but not for check. This commit fixes that. --- internal/config.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/internal/config.go b/internal/config.go index c5430d3..e60b7db 100644 --- a/internal/config.go +++ b/internal/config.go @@ -188,15 +188,31 @@ func CheckConfig() error { if !CheckIfResticIsCallable() { return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, flags.RESTIC_BIN) } - for name, backend := range c.Backends { - backend.name = name - if err := backend.validate(); err != nil { + + cwd, _ := GetPathRelativeToConfig(".") + for name, location := range c.Locations { + location.name = name + + // Hooks before location validation + options := ExecuteOptions{ + Command: "bash", + Dir: cwd, + Envs: map[string]string{ + "AUTORESTIC_LOCATION": location.name, + }, + } + if err := location.ExecuteHooks(location.Hooks.PreValidate, options); err != nil { + return err + } + + if err := location.validate(); err != nil { return err } } - for name, location := range c.Locations { - location.name = name - if err := location.validate(); err != nil { + + for name, backend := range c.Backends { + backend.name = name + if err := backend.validate(); err != nil { return err } }