mirror of https://github.com/mpv-player/mpv
path: simplify "cache" and "state" fallback
Instead of having more global state just do it on-the-fly.
This commit is contained in:
parent
519e56f80f
commit
d8d0c853c0
|
@ -10,8 +10,6 @@ struct mpv_global {
|
||||||
struct mp_client_api *client_api;
|
struct mp_client_api *client_api;
|
||||||
char *configdir;
|
char *configdir;
|
||||||
struct stats_base *stats;
|
struct stats_base *stats;
|
||||||
bool no_cachedir;
|
|
||||||
bool no_statedir;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -84,16 +84,20 @@ static const char *mp_get_platform_path(void *talloc_ctx,
|
||||||
|
|
||||||
// Return the native config path if the platform doesn't support the
|
// Return the native config path if the platform doesn't support the
|
||||||
// type we are trying to fetch.
|
// type we are trying to fetch.
|
||||||
if (strcmp(type, "cache") == 0 && global->no_cachedir)
|
const char *fallback_type = NULL;
|
||||||
type = "home";
|
if (!strcmp(type, "cache") || !strcmp(type, "state"))
|
||||||
if (strcmp(type, "state") == 0 && global->no_statedir)
|
fallback_type = "home";
|
||||||
type = "home";
|
|
||||||
|
|
||||||
for (int n = 0; n < MP_ARRAY_SIZE(path_resolvers); n++) {
|
for (int n = 0; n < MP_ARRAY_SIZE(path_resolvers); n++) {
|
||||||
const char *path = path_resolvers[n](talloc_ctx, type);
|
const char *path = path_resolvers[n](talloc_ctx, type);
|
||||||
if (path && path[0])
|
if (path && path[0])
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fallback_type) {
|
||||||
|
assert(strcmp(fallback_type, type) != 0);
|
||||||
|
return mp_get_platform_path(talloc_ctx, global, fallback_type);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,17 +105,6 @@ void mp_init_paths(struct mpv_global *global, struct MPOpts *opts)
|
||||||
{
|
{
|
||||||
TA_FREEP(&global->configdir);
|
TA_FREEP(&global->configdir);
|
||||||
|
|
||||||
// Check if the platform has unique directories that differ from
|
|
||||||
// the standard config directory.
|
|
||||||
void *tmp = talloc_new(NULL);
|
|
||||||
const char *cache = mp_get_platform_path(tmp, global, "cache");
|
|
||||||
const char *state = mp_get_platform_path(tmp, global, "state");
|
|
||||||
if (!cache)
|
|
||||||
global->no_cachedir = true;
|
|
||||||
if (!state)
|
|
||||||
global->no_statedir = true;
|
|
||||||
talloc_free(tmp);
|
|
||||||
|
|
||||||
const char *force_configdir = getenv("MPV_HOME");
|
const char *force_configdir = getenv("MPV_HOME");
|
||||||
if (opts->force_configdir && opts->force_configdir[0])
|
if (opts->force_configdir && opts->force_configdir[0])
|
||||||
force_configdir = opts->force_configdir;
|
force_configdir = opts->force_configdir;
|
||||||
|
|
Loading…
Reference in New Issue