aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-09-07 18:01:26 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-09-11 18:00:15 +0200
commit04813aa7ea696ee5b022004153389788e8951602 (patch)
tree82befaec6d40102abe7bf08850a6eb51fffd8e20
parentRemove xdg sysconfdir. (diff)
downloadcalp-04813aa7ea696ee5b022004153389788e8951602.tar.gz
calp-04813aa7ea696ee5b022004153389788e8951602.tar.xz
Fixes to xdg basedir.
Update to v0.8 (XDG_STATE_HOME). Allowed empty environment variables alongside unset variables.
-rw-r--r--module/xdg/basedir.scm33
1 files changed, 24 insertions, 9 deletions
diff --git a/module/xdg/basedir.scm b/module/xdg/basedir.scm
index 664f58e3..f4e7b89b 100644
--- a/module/xdg/basedir.scm
+++ b/module/xdg/basedir.scm
@@ -4,50 +4,65 @@
(define-module (xdg basedir)
:export (runtime-dir
- data-home config-home cache-home
+ data-home config-home state-home cache-home
data-dirs config-dirs))
+;;; Check if an environment variable is set to a non-empty value.
+(define (set? var)
+ (cond ((getenv var)
+ => (lambda (s)
+ (if (string-null? s)
+ #f s)))
+ (else #f)))
+
;;; XDG_DATA_HOME
;;; $HOME/.local/share
(define (data-home)
- (or (getenv "XDG_DATA_HOME")
+ (or (set? "XDG_DATA_HOME")
(string-append (getenv "HOME") "/.local/share")))
;;; XDG_CONFIG_HOME
;;; $HOME/.config
(define (config-home)
- (or (getenv "XDG_CONFIG_HOME")
+ (or (set? "XDG_CONFIG_HOME")
(string-append (getenv "HOME") "/.config")))
+;;; XDG_STATE_HOME
+;;; $HOME/.local/state
+(define (state-home)
+ (or (set? "XDG_STATE_HOME")
+ (string-append (getenv "HOME") "/.local/state")))
+
;;; XDG_DATA_DIRS
;;; colon (:) sepparated, in addition to XDG_DATA_HOME
;;; /usr/local/share/:/usr/share/
(define (data-dirs)
- (let ((str (getenv "XDG_DATA_DIRS")))
+ (let ((str (set? "XDG_DATA_DIRS")))
(if str
- (parse-path str)
+ (string-split str #\:)
'("/usr/local/share" "/usr/share"))))
;;; XDG_CONFIG_DIRS
;;; colon (:) separated, in adddition to XDG_CONFIG_HOME
;;; /etc/xdg
(define (config-dirs)
- (let ((str (getenv "XDG_CONFIG_DIRS")))
+ (let ((str (set? "XDG_CONFIG_DIRS")))
(if str
(string-split str #\:)
- (list (string-append sysconfdir "/xdg")))))
+ '("/etc/xdg"))))
;;; XDG_CACHE_HOME
;;; $HOME/.cache
(define (cache-home)
- (or (getenv "XDG_CACHE_HOME")
+ (or (set? "XDG_CACHE_HOME")
(string-append (getenv "HOME") "/.cache")))
;;; XDG_RUNTIME_DIR
;;; Default to /tmp or /tmp/$(uid), and raise a warning
(define (runtime-dir)
- (or (getenv "XDG_RUNTIME_DIR")
+ (or (set? "XDG_RUNTIME_DIR")
(begin
(display "WARNING: XDG_RUNTIME_DIR unset, defaulting to /tmp\n"
(current-error-port))
"/tmp")))
+