From 0803c0fd703f1b475ffcf76a841422c23822557b Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Tue, 30 Apr 2024 05:40:34 -0700 Subject: [PATCH] fix(icq-relayer): return immediately on non-os.IsNotExist errors This change avoids the need to try to brute-force creating an entirely fresh configuration, in the case where an error that isn't a path non-existence error occurs, for example in the case of a permission error on the parent directory or non-matching user/group permissions. Now we check against the returned error after os.Stat and accordingly return immediately or continue to create the configuration. Fixes #1524 --- icq-relayer/cmd/config.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/icq-relayer/cmd/config.go b/icq-relayer/cmd/config.go index 6c3e33bd2..c46190e93 100644 --- a/icq-relayer/cmd/config.go +++ b/icq-relayer/cmd/config.go @@ -24,11 +24,15 @@ func initConfig(cmd *cobra.Command) error { cfgPath := path.Join(home, "config.yaml") _, err = os.Stat(cfgPath) if err != nil { - err = config.CreateConfig(home) - if err != nil { + if !os.IsNotExist(err) { // Return immediately + return err + } + + if err := config.CreateConfig(home); err != nil { return err } } + viper.SetConfigFile(cfgPath) err = viper.ReadInConfig() if err != nil {