0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-19 19:42:24 +02:00

path: don't access global option struct

The path functions need to access the option that forces non-default
config directories. Just add it as a field to mpv_global - it seems
justified. The accessed options were always enforced as immutable after
init, so there's not much of a change.
This commit is contained in:
wm4 2018-05-21 15:49:19 +02:00
parent fe6b2f9103
commit 3569857b75
4 changed files with 20 additions and 7 deletions

View File

@ -8,6 +8,7 @@ struct mpv_global {
struct mp_log *log;
struct m_config_shadow *config;
struct mp_client_api *client_api;
char *configdir;
// Using this is deprecated and should be avoided (missing synchronization).
// Use m_config_cache to access mpv_global.config instead.

View File

@ -61,6 +61,19 @@ static const char *const config_dirs[] = {
"global",
};
void mp_init_paths(struct mpv_global *global, struct MPOpts *opts)
{
TA_FREEP(&global->configdir);
const char *force_configdir = getenv("MPV_HOME");
if (opts->force_configdir && opts->force_configdir[0])
force_configdir = opts->force_configdir;
if (!opts->load_config)
force_configdir = "";
global->configdir = talloc_strdup(global, force_configdir);
}
// 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
// (or its children), as this function can return a statically allocated string.
@ -70,15 +83,10 @@ static const char *mp_get_platform_path(void *talloc_ctx,
{
assert(talloc_ctx);
const char *force_configdir = getenv("MPV_HOME");
if (global->opts->force_configdir && global->opts->force_configdir[0])
force_configdir = global->opts->force_configdir;
if (!global->opts->load_config)
force_configdir = "";
if (force_configdir) {
if (global->configdir) {
for (int n = 0; n < MP_ARRAY_SIZE(config_dirs); n++) {
if (strcmp(config_dirs[n], type) == 0)
return (n == 0 && force_configdir[0]) ? force_configdir : NULL;
return (n == 0 && global->configdir[0]) ? global->configdir : NULL;
}
}

View File

@ -24,6 +24,9 @@
#include "misc/bstr.h"
struct mpv_global;
struct MPOpts;
void mp_init_paths(struct mpv_global *global, struct MPOpts *opts);
// Search for the input filename in several paths. These include user and global
// config locations by default. Some platforms may implement additional platform

View File

@ -338,6 +338,7 @@ int mp_initialize(struct MPContext *mpctx, char **options)
if (options)
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, options);
mp_init_paths(mpctx->global, opts);
mp_update_logging(mpctx, true);
if (options) {