ソースを参照

Respect XDG_CACHE_HOME

The XDG Base Directory specification [1] demands that there should be a
"single base directory relative to which user-specific non-essential
(cached) data should be written". Light currently makes use of such a
cache directory, but hardcodes the default "$HOME/.cache".

In order to enable users to specify a custom cache directory, respect
this convention and use the "$XDG_CACHE_HOME" environment variable if it
is set. If it is not set, fall back to "$HOME/.cache".

[1] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Christoph Böhmwalder 6 年 前
コミット
48615fca6e
共有1 個のファイルを変更した8 個の追加3 個の削除を含む
  1. 8
    3
      src/light.c

+ 8
- 3
src/light.c ファイルの表示

@@ -303,10 +303,15 @@ bool light_initialize(int argc, char **argv)
303 303
 	int rc;
304 304
 
305 305
 	/* Classic SUID root mode or new user based cache files */
306
-	if (geteuid() == 0)
306
+	if (geteuid() == 0) {
307 307
 		snprintf(ctx.prefix, sizeof(ctx.prefix), "%s", "/etc/light");
308
-	else
309
-		snprintf(ctx.prefix, sizeof(ctx.prefix), "%s/.cache/light", getenv("HOME"));
308
+	} else {
309
+		char *xdg_cache = getenv("XDG_CACHE_HOME");
310
+		if (xdg_cache != NULL)
311
+			snprintf(ctx.prefix, sizeof(ctx.prefix), "%s/light", xdg_cache);
312
+		else
313
+			snprintf(ctx.prefix, sizeof(ctx.prefix), "%s/.cache/light", getenv("HOME"));
314
+	}
310 315
 
311 316
 	light_defaults();
312 317
 	if (!light_parse_args(argc, argv)) {