clerk/internal/xdg/state.go (view raw)
| 1 | package xdg |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | ) |
| 7 | |
| 8 | // StateDir returns the base directory for user-specific state data, |
| 9 | // per the XDG Base Directory Specification: $XDG_STATE_HOME if it is set to |
| 10 | // an absolute path, otherwise the platform-specific default. |
| 11 | // Vendored from github.com/adrg/xdg (MIT), StateHome. |
| 12 | func StateDir() (string, error) { |
| 13 | if dir := os.Getenv("XDG_STATE_HOME"); dir != "" && filepath.IsAbs(dir) { |
| 14 | return dir, nil |
| 15 | } |
| 16 | home, err := os.UserHomeDir() |
| 17 | if err != nil { |
| 18 | return "", err |
| 19 | } |
| 20 | return defaultStateDir(home), nil |
| 21 | } |