Revert "various: remove unneeded option path expansion handling"

Fixes #16573.

This reverts commit 137d5374bd.
This commit is contained in:
Dudemanguy
2025-08-07 19:15:12 -05:00
parent 6a5eb8c229
commit 2b74582fcb
14 changed files with 27 additions and 17 deletions

View File

@@ -105,7 +105,7 @@ struct demux_cache *demux_cache_create(struct mpv_global *global,
char *cache_dir = cache->opts->cache_dir;
if (cache_dir && cache_dir[0]) {
cache_dir = talloc_strdup(NULL, cache_dir);
cache_dir = mp_get_user_path(NULL, global, cache_dir);
} else {
cache_dir = mp_find_user_file(NULL, global, "cache", "");
}

View File

@@ -1649,6 +1649,8 @@ static bool parse_config_file(struct input_ctx *ictx, char *file)
bool r = false;
void *tmp = talloc_new(NULL);
file = mp_get_user_path(tmp, ictx->global, file);
bstr data = stream_read_file2(file, tmp, STREAM_ORIGIN_DIRECT | STREAM_READ,
ictx->global, 1000000);
if (data.start) {

View File

@@ -389,7 +389,7 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api,
*arg = (struct mp_ipc_ctx){
.log = mp_log_new(arg, global->log, "ipc"),
.client_api = client_api,
.path = talloc_strdup(arg, opts->ipc_path),
.path = mp_get_user_path(arg, global, opts->ipc_path),
.death_pipe = {-1, -1},
};

View File

@@ -6957,9 +6957,8 @@ static void cmd_load_input_conf(void *p)
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
char *config_file = mp_get_user_path(NULL, mpctx->global, cmd->args[0].v.s);
char *config_file = cmd->args[0].v.s;
cmd->success = mp_input_load_config_file(mpctx->input, config_file);
talloc_free(config_file);
}
static void cmd_load_script(void *p)

View File

@@ -201,7 +201,7 @@ char *mp_get_playback_resume_dir(struct MPContext *mpctx)
{
char *wl_dir = mpctx->opts->watch_later_dir;
if (wl_dir && wl_dir[0]) {
wl_dir = talloc_strdup(NULL, wl_dir);
wl_dir = mp_get_user_path(NULL, mpctx->global, wl_dir);
} else {
wl_dir = mp_find_user_file(NULL, mpctx->global, "state", MP_WATCH_LATER_CONF);
}

View File

@@ -1548,7 +1548,8 @@ static void append_to_watch_history(struct MPContext *mpctx)
return;
void *ctx = talloc_new(NULL);
char *history_path = mpctx->opts->watch_history_path;
char *history_path = mp_get_user_path(ctx, mpctx->global,
mpctx->opts->watch_history_path);
char *history_path_dir = bstrto0(ctx, mp_dirname(history_path));
mp_mkdirp(history_path_dir);

View File

@@ -297,6 +297,7 @@ static char *gen_fname(struct mp_cmd_ctx *cmd, const char *file_ext)
char *dir = ctx->mpctx->opts->screenshot_dir;
if (dir && dir[0]) {
void *t = fname;
dir = mp_get_user_path(t, ctx->mpctx->global, dir);
fname = mp_path_join(NULL, dir, fname);
mp_mkdirp(dir);

View File

@@ -280,7 +280,7 @@ bool mp_load_scripts(struct MPContext *mpctx)
char **files = mpctx->opts->script_files;
for (int n = 0; files && files[n]; n++) {
if (files[n][0])
ok &= mp_load_script(mpctx, files[n]) >= 0;
ok &= mp_load_user_script(mpctx, files[n]) >= 0;
}
if (!mpctx->opts->auto_load_scripts)
return ok;

View File

@@ -131,7 +131,7 @@ ASS_Library *mp_ass_init(struct mpv_global *global,
struct osd_style_opts *opts, struct mp_log *log)
{
char *path = opts->fonts_dir && opts->fonts_dir[0] ?
talloc_strdup(NULL, opts->fonts_dir) :
mp_get_user_path(NULL, global, opts->fonts_dir) :
mp_find_config_file(NULL, global, "fonts");
mp_dbg(log, "ASS library version: 0x%x (runtime 0x%x)\n",
(unsigned)LIBASS_VERSION, ass_library_version());

View File

@@ -750,7 +750,7 @@ static struct mp_filter *vf_vapoursynth_create(struct mp_filter *parent,
MP_FATAL(p, "'file' parameter must be set.\n");
goto error;
}
p->script_path = talloc_strdup(p, p->opts->file);
p->script_path = mp_get_user_path(p, f->global, p->opts->file);
p->max_requests = p->opts->maxrequests;
if (p->max_requests < 0)

View File

@@ -73,10 +73,11 @@ static void load_profile(struct gl_lcms *p)
if (!p->opts->profile || !p->opts->profile[0])
return;
char *fname = p->opts->profile;
char *fname = mp_get_user_path(NULL, p->global, p->opts->profile);
MP_VERBOSE(p, "Opening ICC profile '%s'\n", fname);
struct bstr iccdata = stream_read_file(fname, p, p->global,
100000000); // 100 MB
talloc_free(fname);
if (!iccdata.len)
return;
@@ -364,7 +365,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
char *cache_dir = p->opts->cache_dir;
if (cache_dir && cache_dir[0]) {
cache_dir = talloc_strdup(tmp, cache_dir);
cache_dir = mp_get_user_path(tmp, p->global, cache_dir);
} else {
cache_dir = mp_find_user_file(tmp, p->global, "cache", "");
}

View File

@@ -559,7 +559,7 @@ void gl_sc_set_cache_dir(struct gl_shader_cache *sc, char *dir)
{
talloc_free(sc->cache_dir);
if (dir && dir[0]) {
dir = talloc_strdup(NULL, dir);
dir = mp_get_user_path(NULL, sc->global, dir);
} else {
dir = mp_find_user_file(NULL, sc->global, "cache", "");
}

View File

@@ -583,7 +583,9 @@ static struct bstr load_cached_file(struct gl_video *p, const char *path)
return p->files[n].body;
}
// not found -> load it
struct bstr s = stream_read_file(path, p, p->global, 1000000000); // 1GB
char *fname = mp_get_user_path(NULL, p->global, path);
struct bstr s = stream_read_file(fname, p, p->global, 1000000000); // 1GB
talloc_free(fname);
if (s.len) {
struct cached_file new = {
.path = talloc_strdup(p, path),

View File

@@ -1826,7 +1826,7 @@ static void cache_init(struct vo *vo, struct cache *cache, size_t max_size,
char *dir;
if (dir_opt && dir_opt[0]) {
dir = talloc_strdup(vo, dir_opt);
dir = mp_get_user_path(vo, p->global, dir_opt);
} else {
dir = mp_find_user_file(vo, p->global, "cache", "");
}
@@ -2128,7 +2128,9 @@ static const struct pl_hook *load_hook(struct priv *p, const char *path)
return p->user_hooks[i].hook;
}
bstr shader = stream_read_file(path, p, p->global, 1000000000); // 1GB
char *fname = mp_get_user_path(NULL, p->global, path);
bstr shader = stream_read_file(fname, p, p->global, 1000000000); // 1GB
talloc_free(fname);
const struct pl_hook *hook = NULL;
if (shader.len)
@@ -2171,9 +2173,10 @@ static void update_icc_opts(struct priv *p, const struct mp_icc_opts *opts)
if (p->icc_path && strcmp(opts->profile, p->icc_path) == 0)
return; // ICC profile hasn't changed
char *fname = opts->profile;
char *fname = mp_get_user_path(NULL, p->global, opts->profile);
MP_VERBOSE(p, "Opening ICC profile '%s'\n", fname);
struct bstr icc = stream_read_file(fname, p, p->global, 100000000); // 100 MB
talloc_free(fname);
update_icc(p, icc);
// Update cached path
@@ -2196,7 +2199,7 @@ static void update_lut(struct priv *p, struct user_lut *lut)
talloc_replace(p, lut->path, lut->opt);
// Load LUT file
char *fname = lut->path;
char *fname = mp_get_user_path(NULL, p->global, lut->path);
MP_VERBOSE(p, "Loading custom LUT '%s'\n", fname);
const int lut_max_size = 1536 << 20; // 1.5 GiB, matches lut cache limit
struct bstr lutdata = stream_read_file(fname, NULL, p->global, lut_max_size);
@@ -2206,6 +2209,7 @@ static void update_lut(struct priv *p, struct user_lut *lut)
} else {
lut->lut = pl_lut_parse_cube(p->pllog, lutdata.start, lutdata.len);
}
talloc_free(fname);
talloc_free(lutdata.start);
}