diff options
author | sfan5 <sfan5@live.de> | 2023-05-20 20:04:42 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-05-21 20:11:24 +0200 |
commit | d8d0c853c018814dcbc70771ddb6d7f83e115cfc (patch) | |
tree | ba6d8ed84b091b5cf429c83db1105cd66421ec4d /options/path.c | |
parent | 519e56f80f8f251c96682daaa90f409c05277464 (diff) | |
download | mpv-d8d0c853c018814dcbc70771ddb6d7f83e115cfc.tar.bz2 mpv-d8d0c853c018814dcbc70771ddb6d7f83e115cfc.tar.xz |
path: simplify "cache" and "state" fallback
Instead of having more global state just do it on-the-fly.
Diffstat (limited to 'options/path.c')
-rw-r--r-- | options/path.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/options/path.c b/options/path.c index e1aaa48907..c9a986fe81 100644 --- a/options/path.c +++ b/options/path.c @@ -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 // type we are trying to fetch. - if (strcmp(type, "cache") == 0 && global->no_cachedir) - type = "home"; - if (strcmp(type, "state") == 0 && global->no_statedir) - type = "home"; + const char *fallback_type = NULL; + if (!strcmp(type, "cache") || !strcmp(type, "state")) + fallback_type = "home"; for (int n = 0; n < MP_ARRAY_SIZE(path_resolvers); n++) { const char *path = path_resolvers[n](talloc_ctx, type); if (path && path[0]) return path; } + + if (fallback_type) { + assert(strcmp(fallback_type, type) != 0); + return mp_get_platform_path(talloc_ctx, global, fallback_type); + } return NULL; } @@ -101,17 +105,6 @@ void mp_init_paths(struct mpv_global *global, struct MPOpts *opts) { 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"); if (opts->force_configdir && opts->force_configdir[0]) force_configdir = opts->force_configdir; |