config: handle --no-config case directly in mp_config_dirs()

Requires less special-casing, and probably also avoids that starting mpv
with --no-config creates a config dir (even if nothing is loaded).
This commit is contained in:
wm4 2014-06-26 19:20:41 +02:00
parent b4d64ac434
commit 7f55a39646
1 changed files with 23 additions and 26 deletions

View File

@ -103,10 +103,15 @@ static void mp_add_xdg_config_dirs(struct mpv_global *global, char **dirs, int i
// priority
static char **mp_config_dirs(void *talloc_ctx, struct mpv_global *global)
{
struct MPOpts *opts = global->opts;
char **ret = talloc_zero_array(talloc_ctx, char*, MAX_CONFIG_PATHS);
if (global->opts->force_configdir && global->opts->force_configdir[0]) {
ret[0] = talloc_strdup(ret, global->opts->force_configdir);
if (!opts->load_config)
return ret;
if (opts->force_configdir && opts->force_configdir[0]) {
ret[0] = talloc_strdup(ret, opts->force_configdir);
return ret;
}
@ -134,10 +139,7 @@ static char **mp_config_dirs(void *talloc_ctx, struct mpv_global *global)
char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global,
const char *filename)
{
struct MPOpts *opts = global->opts;
char *res = NULL;
if (opts->load_config) {
char **dirs = mp_config_dirs(NULL, global);
for (int i = 0; dirs && dirs[i]; i++) {
char *file = talloc_asprintf(talloc_ctx, "%s/%s", dirs[i], filename);
@ -150,7 +152,6 @@ char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global,
talloc_free(file);
}
talloc_free(dirs);
}
MP_VERBOSE(global, "config path: '%s' -> '%s'\n", filename,
res ? res : "(NULL)");
@ -160,12 +161,9 @@ char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global,
char **mp_find_all_config_files(void *talloc_ctx, struct mpv_global *global,
const char *filename)
{
struct MPOpts *opts = global->opts;
char **ret = talloc_zero_array(talloc_ctx, char*, MAX_CONFIG_PATHS + 1);
int num_ret = 0;
if (opts->load_config) {
char **dirs = mp_config_dirs(NULL, global);
for (int i = 0; dirs && dirs[i]; i++) {
char *file = talloc_asprintf(ret, "%s/%s", dirs[i], filename);
@ -176,7 +174,6 @@ char **mp_find_all_config_files(void *talloc_ctx, struct mpv_global *global,
ret[num_ret++] = file;
}
talloc_free(dirs);
}
for (int n = 0; n < num_ret / 2; n++)
MPSWAP(char*, ret[n], ret[num_ret - n - 1]);