diff options
Diffstat (limited to 'lib/xdg')
-rw-r--r-- | lib/xdg/xdg.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/xdg/xdg.go b/lib/xdg/xdg.go index 6060c2bc..0c578fad 100644 --- a/lib/xdg/xdg.go +++ b/lib/xdg/xdg.go @@ -67,6 +67,19 @@ func DataPath(paths ...string) string { return res } +// Return a path relative to the user state home dir +func StatePath(paths ...string) string { + res := filepath.Join(paths...) + if !filepath.IsAbs(res) { + data := os.Getenv("XDG_STATE_HOME") + if data == "" { + data = ExpandHome("~/.local/state") + } + res = filepath.Join(data, res) + } + return res +} + // ugly: there's no other way to allow mocking a function in go... var userRuntimePath = func() string { uid := strconv.Itoa(os.Getuid()) |