Fix home user directory detection handling (#145)

This commit is contained in:
Thomas Miceli 2023-10-31 15:23:15 +09:00 committed by GitHub
parent 064d4d53f6
commit dcacde0959
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,14 +52,10 @@ type config struct {
} }
func configWithDefaults() (*config, error) { func configWithDefaults() (*config, error) {
homeDir, err := os.UserHomeDir()
c := &config{} c := &config{}
if err != nil {
return c, err
}
c.LogLevel = "warn" c.LogLevel = "warn"
c.OpengistHome = filepath.Join(homeDir, ".opengist") c.OpengistHome = ""
c.DBFilename = "opengist.db" c.DBFilename = "opengist.db"
c.SqliteJournalMode = "WAL" c.SqliteJournalMode = "WAL"
@ -93,6 +89,15 @@ func InitConfig(configPath string) error {
return err 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 { if err = checks(c); err != nil {
return err return err
} }