From 499dce5ba127e8dde11e25d720881cb0646d55f9 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Mon, 4 Sep 2023 16:58:59 -0500 Subject: [PATCH] path-{darwin,unix}: save cache to subdir when using non-XDG path mpv saves cache by default nowadays, but vo_gpu is pretty spammy and saves a bunch of files per shader. If someone is using the non-XDG config directory, this all gets dumped directly into ~/.mpv which isn't so nice. Save it to a sub directory called "cache" instead (or alternatively submit to your XDG overlords). For unfortunate reasons, macOS uses XDG_CONFIG_HOME and has the same legacy fallback mechanism, so this applies to it too. --- osdep/path-darwin.c | 8 ++++++-- osdep/path-unix.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/osdep/path-darwin.c b/osdep/path-darwin.c index 4382def498..0b55ea4c56 100644 --- a/osdep/path-darwin.c +++ b/osdep/path-darwin.c @@ -28,6 +28,7 @@ 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 old_cache[512]; static void path_init(void) { @@ -41,8 +42,10 @@ static void path_init(void) } // Maintain compatibility with old ~/.mpv - if (home && home[0]) + if (home && home[0]) { snprintf(old_home, sizeof(old_home), "%s/.mpv", home); + snprintf(old_cache, sizeof(old_cache), "%s/.mpv/cache", home); + } if (home && home[0]) snprintf(mpv_cache, sizeof(mpv_cache), "%s/Library/Caches/io.mpv", home); @@ -51,8 +54,9 @@ static void path_init(void) // config dir only. 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_cache, sizeof(mpv_cache), "%s", old_cache); old_home[0] = '\0'; + old_cache[0] = '\0'; } } diff --git a/osdep/path-unix.c b/osdep/path-unix.c index 4a41a4d924..fed2695a87 100644 --- a/osdep/path-unix.c +++ b/osdep/path-unix.c @@ -29,6 +29,7 @@ static pthread_once_t path_init_once = PTHREAD_ONCE_INIT; static char mpv_home[CONF_MAX]; static char old_home[CONF_MAX]; static char mpv_cache[CONF_MAX]; +static char old_cache[CONF_MAX]; static char mpv_state[CONF_MAX]; #define MKPATH(BUF, ...) (snprintf((BUF), CONF_MAX, __VA_ARGS__) >= CONF_MAX) @@ -47,8 +48,10 @@ static void path_init(void) } // Maintain compatibility with old ~/.mpv - if (home && home[0]) + if (home && home[0]) { err = err || MKPATH(old_home, "%s/.mpv", home); + err = err || MKPATH(old_cache, "%s/.mpv/cache", home); + } if (xdg_cache && xdg_cache[0]) { err = err || MKPATH(mpv_cache, "%s/mpv", xdg_cache); @@ -66,9 +69,10 @@ 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)) { err = err || MKPATH(mpv_home, "%s", old_home); - err = err || MKPATH(mpv_cache, "%s", old_home); + err = err || MKPATH(mpv_cache, "%s", old_cache); err = err || MKPATH(mpv_state, "%s", old_home); old_home[0] = '\0'; + old_cache[0] = '\0'; } if (err) {