Skip to content

Commit

Permalink
Fix home user directory detection handling (thomiceli#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli committed Oct 31, 2023
1 parent 064d4d5 commit dcacde0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit dcacde0

Please sign in to comment.