Skip to content

Commit

Permalink
Update cli/lakeflags/datadir.go
Browse files Browse the repository at this point in the history
Co-authored-by: Noah Treuhaft <[email protected]>
  • Loading branch information
mattnibs and nwt authored Sep 29, 2023
1 parent ff88fe9 commit 537e57e
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions cli/lakeflags/datadir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 537e57e

Please sign in to comment.