From dcacde09595fafeddefa48bcd63c6cdd29e501ba Mon Sep 17 00:00:00 2001 From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:23:15 +0900 Subject: [PATCH] Fix home user directory detection handling (#145) --- internal/config/config.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 66f9ecd..358f71b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -52,14 +52,10 @@ type config struct { } func configWithDefaults() (*config, error) { - homeDir, err := os.UserHomeDir() c := &config{} - if err != nil { - return c, err - } c.LogLevel = "warn" - c.OpengistHome = filepath.Join(homeDir, ".opengist") + c.OpengistHome = "" c.DBFilename = "opengist.db" c.SqliteJournalMode = "WAL" @@ -93,6 +89,15 @@ func InitConfig(configPath string) error { return err } + if c.OpengistHome == "" { + homeDir, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("opengist home directory is not set and current user home directory could not be determined; please specify the opengist home directory manually via the configuration") + } + + c.OpengistHome = filepath.Join(homeDir, ".opengist") + } + if err = checks(c); err != nil { return err }