mirror of
https://github.com/mpv-player/mpv
synced 2024-12-29 10:32:15 +00:00
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
This commit is contained in:
parent
d8d0c853c0
commit
576e86bfa1
@ -64,6 +64,12 @@ static const char *const config_dirs[] = {
|
|||||||
"exe_dir",
|
"exe_dir",
|
||||||
"global",
|
"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.
|
// 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
|
// 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);
|
assert(talloc_ctx);
|
||||||
|
|
||||||
bool config_dir = strcmp(type, "cache") != 0 && strcmp(type, "state") != 0;
|
if (global->configdir) {
|
||||||
if (global->configdir && config_dir) {
|
// force all others to NULL, only first returns the path
|
||||||
for (int n = 0; n < MP_ARRAY_SIZE(config_dirs); n++) {
|
for (int n = 0; n < MP_ARRAY_SIZE(config_dirs); n++) {
|
||||||
if (strcmp(config_dirs[n], type) == 0)
|
if (strcmp(config_dirs[n], type) == 0)
|
||||||
return (n == 0 && global->configdir[0]) ? global->configdir : NULL;
|
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
|
// 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)
|
if (res)
|
||||||
res = mp_path_join(talloc_ctx, res, filename);
|
res = mp_path_join(talloc_ctx, res, filename);
|
||||||
talloc_free(tmp);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user