getDefaultDataDir returns the default data directory for the current user. Derived from https://github.com/btcsuite/btcd/blob/master/btcutil/appdata.go
()
| 9 | // getDefaultDataDir returns the default data directory for the current user. |
| 10 | // Derived from https://github.com/btcsuite/btcd/blob/master/btcutil/appdata.go |
| 11 | func getDefaultDataDir() string { |
| 12 | // Resolve the XDG data home directory if set. |
| 13 | if xdgDataHome := os.Getenv("XDG_DATA_HOME"); xdgDataHome != "" { |
| 14 | return filepath.Join(xdgDataHome, "super") |
| 15 | } |
| 16 | if runtime.GOOS == "windows" { |
| 17 | if appData := os.Getenv("LOCALAPPDATA"); appData != "" { |
| 18 | return filepath.Join(appData, "super") |
| 19 | } |
| 20 | } |
| 21 | if homeDir, _ := os.UserHomeDir(); homeDir != "" { |
| 22 | // Follow the XDG spec which states: |
| 23 | // If $XDG_DATA_HOME is either not set or empty, a default equal to |
| 24 | // $HOME/.local/share should be used. |
| 25 | return filepath.Join(homeDir, ".local", "share", "super") |
| 26 | } |
| 27 | // Return an empty string which will cause an error if a default data |
| 28 | // directory cannot be found. |
| 29 | return "" |
| 30 | } |