From 4502522a7aee093c923e79a65e4684ea2634af30 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Tue, 2 May 2023 19:42:23 -0500 Subject: player: use XDG_CACHE_HOME by default This adds cache as a possible path for mpv to internally pick (~/.cache/mpv for non-darwin unix-like systems, the usual config directory for everyone else). For gpu shader cache and icc cache, controlling whether or not to write such files is done with the new --gpu-shader-cache and --icc-cache options respectively. Additionally, --cache-on-disk no longer requires explicitly setting the --cache-dir option. The old options, --cache-dir, --gpu-shader-cache-dir, and --icc-cache-dir simply set an override for the directory to save cache files. If unset, then the cache is saved in XDG_CACHE_HOME. --- osdep/path-unix.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'osdep/path-unix.c') diff --git a/osdep/path-unix.c b/osdep/path-unix.c index 34187b430e..5dc5cb2836 100644 --- a/osdep/path-unix.c +++ b/osdep/path-unix.c @@ -27,11 +27,13 @@ static pthread_once_t path_init_once = PTHREAD_ONCE_INIT; static char mpv_home[512]; static char old_home[512]; +static char mpv_cache[512]; static char mpv_state[512]; static void path_init(void) { char *home = getenv("HOME"); + char *xdg_cache = getenv("XDG_CACHE_HOME"); char *xdg_config = getenv("XDG_CONFIG_HOME"); char *xdg_state = getenv("XDG_STATE_HOME"); @@ -45,6 +47,12 @@ static void path_init(void) if (home && home[0]) snprintf(old_home, sizeof(old_home), "%s/.mpv", home); + if (xdg_cache && xdg_cache[0]) { + snprintf(mpv_cache, sizeof(mpv_cache), "%s/mpv", xdg_cache); + } else if (home && home[0]) { + snprintf(mpv_cache, sizeof(mpv_cache), "%s/.cache/mpv", home); + } + if (xdg_state && xdg_state[0]) { snprintf(mpv_state, sizeof(mpv_state), "%s/mpv", xdg_state); } else if (home && home[0]) { @@ -55,6 +63,7 @@ static void path_init(void) // config dir only. Also do not use any other XDG directories. if (mp_path_exists(old_home) && !mp_path_exists(mpv_home)) { snprintf(mpv_home, sizeof(mpv_home), "%s", old_home); + snprintf(mpv_cache, sizeof(mpv_cache), "%s", old_home); snprintf(mpv_state, sizeof(mpv_state), "%s", old_home); old_home[0] = '\0'; } @@ -67,6 +76,8 @@ const char *mp_get_platform_path_unix(void *talloc_ctx, const char *type) return mpv_home; if (strcmp(type, "old_home") == 0) return old_home; + if (strcmp(type, "cache") == 0) + return mpv_cache; if (strcmp(type, "state") == 0) return mpv_state; if (strcmp(type, "global") == 0) -- cgit v1.2.3