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.
This commit is contained in:
Duru Can Celasun 2025-03-22 18:12:36 +00:00 committed by GitHub
parent 39f4f87ce3
commit bb29a98614
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -188,15 +188,31 @@ func CheckConfig() error {
if !CheckIfResticIsCallable() { if !CheckIfResticIsCallable() {
return fmt.Errorf(`%s was not found. Install either with "autorestic install" or manually`, flags.RESTIC_BIN) 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 cwd, _ := GetPathRelativeToConfig(".")
if err := backend.validate(); err != nil { 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 return err
} }
} }
for name, location := range c.Locations {
location.name = name for name, backend := range c.Backends {
if err := location.validate(); err != nil { backend.name = name
if err := backend.validate(); err != nil {
return err return err
} }
} }