diff options
author | sfan5 <sfan5@live.de> | 2023-05-20 20:10:18 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-05-21 20:11:24 +0200 |
commit | 576e86bfa18a0a79e591988ad93ed009edc40849 (patch) | |
tree | 4e0f6a76b0121fff6f472e38af96c8a4441e729e | |
parent | d8d0c853c018814dcbc70771ddb6d7f83e115cfc (diff) | |
download | mpv-576e86bfa18a0a79e591988ad93ed009edc40849.tar.bz2 mpv-576e86bfa18a0a79e591988ad93ed009edc40849.tar.xz |
path: let configdir also override "cache" and "state" paths
This matches the behaviour that libmpv API clients expect better and
prevents silent regressons with watch_later suddenly appearing in
an entirely different path (or none at all in case of weird platforms*).
Also added some comments for easier understanding.
* Android
-rw-r--r-- | options/path.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/options/path.c b/options/path.c index c9a986fe81..8975291d88 100644 --- a/options/path.c +++ b/options/path.c @@ -64,6 +64,12 @@ static const char *const config_dirs[] = { "exe_dir", "global", }; +// types that configdir replaces (if set) +// These are not part of any fallback order so need to be overriden separately. +static const char *const config_dir_replaces[] = { + "state", + "cache", +}; // Return a platform specific path using a path type as defined in osdep/path.h. // Keep in mind that the only way to free the return value is freeing talloc_ctx @@ -74,12 +80,16 @@ static const char *mp_get_platform_path(void *talloc_ctx, { assert(talloc_ctx); - bool config_dir = strcmp(type, "cache") != 0 && strcmp(type, "state") != 0; - if (global->configdir && config_dir) { + if (global->configdir) { + // force all others to NULL, only first returns the path for (int n = 0; n < MP_ARRAY_SIZE(config_dirs); n++) { if (strcmp(config_dirs[n], type) == 0) return (n == 0 && global->configdir[0]) ? global->configdir : NULL; } + for (int n = 0; n < MP_ARRAY_SIZE(config_dir_replaces); n++) { + if (strcmp(config_dir_replaces[n], type) == 0) + return global->configdir[0] ? global->configdir : NULL; + } } // Return the native config path if the platform doesn't support the @@ -122,7 +132,7 @@ char *mp_find_user_file(void *talloc_ctx, struct mpv_global *global, if (res) res = mp_path_join(talloc_ctx, res, filename); talloc_free(tmp); - MP_DBG(global, "path: '%s' -> '%s'\n", filename, res ? res : "-"); + MP_DBG(global, "%s path: '%s' -> '%s'\n", type, filename, res ? res : "-"); return res; } |