aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/history.go4
-rw-r--r--lib/xdg/xdg.go13
2 files changed, 15 insertions, 2 deletions
diff --git a/commands/history.go b/commands/history.go
index 0a7d6894..576c04b9 100644
--- a/commands/history.go
+++ b/commands/history.go
@@ -91,9 +91,9 @@ func (h *cmdHistory) initialize() {
var err error
openFlags := os.O_RDWR | os.O_EXCL
- histPath := xdg.CachePath("aerc", "history")
+ histPath := xdg.StatePath("aerc", "history")
if _, err := os.Stat(histPath); os.IsNotExist(err) {
- _ = os.MkdirAll(xdg.CachePath("aerc"), 0o700) // caught by OpenFile
+ _ = os.MkdirAll(xdg.StatePath("aerc"), 0o700) // caught by OpenFile
openFlags |= os.O_CREATE
}
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())