From 537e57e0ab424837a0d4b9494779f97f06896193 Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Thu, 28 Sep 2023 23:32:11 -0500 Subject: [PATCH] Update cli/lakeflags/datadir.go Co-authored-by: Noah Treuhaft --- cli/lakeflags/datadir.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/cli/lakeflags/datadir.go b/cli/lakeflags/datadir.go index 1cd5d19971..e175421c6b 100644 --- a/cli/lakeflags/datadir.go +++ b/cli/lakeflags/datadir.go @@ -20,30 +20,16 @@ func getDefaultDataDir() string { if xdgDataHome := os.Getenv("XDG_DATA_HOME"); xdgDataHome != "" { return filepath.Join(xdgDataHome, "zed") } - // Get the OS specific home directory via the Go standard lib. - var homeDir string - usr, err := user.Current() - if err == nil { - homeDir = usr.HomeDir - } - // Fall back to standard HOME environment variable that works - // for most POSIX OSes if the directory from the Go standard - // lib failed. - if err != nil || homeDir == "" { - homeDir = os.Getenv("HOME") - } - switch runtime.GOOS { - case "windows": + if runtime.GOOS == "windows" { if appData := os.Getenv("LOCALAPPDATA"); appData != "" { return filepath.Join(appData, "zed") } - default: - if homeDir != "" { - // For linux and windows follow the XDG spec which states: - // If $XDG_DATA_HOME is either not set or empty, a default equal to - // $HOME/.local/share should be used. - return filepath.Join(homeDir, ".local", "share", "zed") - } + } + if homeDir, _ := os.UserHomeDir(); homeDir != "" { + // Follow the XDG spec which states: + // If $XDG_DATA_HOME is either not set or empty, a default equal to + // $HOME/.local/share should be used. + return filepath.Join(homeDir, ".local", "share", "zed") } // Return an empty string which will cause an error if a default data // directory cannot be found.