ensure config is loaded before lock

This commit is contained in:
2021-11-23 12:32:35 +01:00
parent 26de4385ea
commit 252968e15e
5 changed files with 43 additions and 30 deletions

View File

@@ -19,8 +19,14 @@ func getLock() *viper.Viper {
once.Do(func() {
lock = viper.New()
lock.SetDefault("running", false)
p := path.Dir(viper.ConfigFileUsed())
file = path.Join(p, ".autorestic.lock.yml")
p := viper.ConfigFileUsed()
colors.Primary.Println(p)
if p == "" {
colors.Error.Println("cannot lock before reading config location")
os.Exit(1)
}
file = path.Join(path.Dir(p), ".autorestic.lock.yml")
colors.Faint.Println("Using lock:\t", file)
lock.SetConfigFile(file)
lock.SetConfigType("yml")
lock.ReadInConfig()