summaryrefslogtreecommitdiffstats
path: root/options/path.c
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-05-02 19:29:27 -0500
committerDudemanguy <random342@airmail.cc>2023-05-09 20:37:17 +0000
commit7c4c9bc86f55f4d1224814fbeafdee8f1c3c3108 (patch)
tree049c5f74a1380fd5de1c1911a4829103c875d146 /options/path.c
parent5158b85b21b9316b610ab59ba65da36144e03b9a (diff)
downloadmpv-7c4c9bc86f55f4d1224814fbeafdee8f1c3c3108.tar.bz2
mpv-7c4c9bc86f55f4d1224814fbeafdee8f1c3c3108.tar.xz
player: use XDG_STATE_HOME for watch_later
A pain point for some users is the fact that watch_later is stored in the ~/.config directory when it's really not configuration data. Roughly 2 years ago, XDG_STATE_DIR was added to the XDG Base Directory Specification[0] and its description, user-specific state data, actually perfectly matches what watch_later data is for. Let's go ahead and use this directory as the default for watch_later. This change only affects non-darwin unix-like systems (i.e. Linux, BSDs, etc.). The directory doesn't move for anyone else. Internally, quite a few things change with regards to the path selection. If the platform in question does not have a statedir concept, then the path selection will simply return "home" instead (old behavior). Fixes #9147. [0]: https://gitlab.freedesktop.org/xdg/xdg-specs/-/commit/4f2884e16db35f2962d9b64312917c81be5cb54b
Diffstat (limited to 'options/path.c')
-rw-r--r--options/path.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/options/path.c b/options/path.c
index bd8adf6d81..4ea7269d01 100644
--- a/options/path.c
+++ b/options/path.c
@@ -65,19 +65,6 @@ 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.
@@ -87,13 +74,19 @@ static const char *mp_get_platform_path(void *talloc_ctx,
{
assert(talloc_ctx);
- if (global->configdir) {
+ bool config_dir = strcmp(type, "state") != 0;
+ if (global->configdir && config_dir) {
for (int n = 0; n < MP_ARRAY_SIZE(config_dirs); n++) {
if (strcmp(config_dirs[n], type) == 0)
return (n == 0 && global->configdir[0]) ? global->configdir : NULL;
}
}
+ // Return the native config path if the platform doesn't support the
+ // type we are trying to fetch.
+ if (strcmp(type, "state") == 0 && global->no_statedir)
+ 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])
@@ -102,6 +95,27 @@ static const char *mp_get_platform_path(void *talloc_ctx,
return NULL;
}
+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 *state = mp_get_platform_path(tmp, global, "state");
+ 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;
+ if (!opts->load_config)
+ force_configdir = "";
+
+ global->configdir = talloc_strdup(global, force_configdir);
+}
+
char *mp_find_user_file(void *talloc_ctx, struct mpv_global *global,
const char *type, const char *filename)
{