Skip to content

Commit

Permalink
incus: Handle non-existent home directory
Browse files Browse the repository at this point in the history
Closes lxc#422

Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Jan 23, 2024
1 parent f4ea7c1 commit 36443d5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/incus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,22 @@ func (c *cmdGlobal) PreRun(cmd *cobra.Command, args []string) error {
var configDir string
if os.Getenv("INCUS_CONF") != "" {
configDir = os.Getenv("INCUS_CONF")
} else if os.Getenv("HOME") != "" {
} else if os.Getenv("HOME") != "" && util.PathExists(os.Getenv("HOME")) {
configDir = path.Join(os.Getenv("HOME"), ".config", "incus")
} else {
user, err := user.Current()
if err != nil {
return err
}

configDir = path.Join(user.HomeDir, ".config", "incus")
if util.PathExists(user.HomeDir) {
configDir = path.Join(user.HomeDir, ".config", "incus")
}
}

// If no homedir could be found, treat as if --force-local was passed.
if configDir == "" {
c.flagForceLocal = true
}

c.confPath = os.ExpandEnv(path.Join(configDir, "config.yml"))
Expand Down

0 comments on commit 36443d5

Please sign in to comment.