diff options
author | David Robillard <d@drobilla.net> | 2020-12-01 10:23:54 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-12-01 10:23:54 +0100 |
commit | 3e19bbfc801e2f983c857797b36f8c7ab3d95d60 (patch) | |
tree | 0fff58922382f5b706275e48ba39daacb009fbb4 /src | |
parent | 375cc69f6de5c75e0c2091696a406163d59b536e (diff) | |
download | lilv-3e19bbfc801e2f983c857797b36f8c7ab3d95d60.tar.gz lilv-3e19bbfc801e2f983c857797b36f8c7ab3d95d60.tar.bz2 lilv-3e19bbfc801e2f983c857797b36f8c7ab3d95d60.zip |
Use the canonical path for state directories
This fixes an issue on MacOS if hosts use a temporary directory generated with
mkdtemp, which can create paths that involve symlinks. This is problematic
since the parent directory comparisons here need to determine if a file is
really in one of the state directories. The actual paths here shouldn't be
visible in saved state, so resolve them fully so that the directory membership
tests work correctly and copies and/or links are created when necessary.
Diffstat (limited to 'src')
-rw-r--r-- | src/state.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/state.c b/src/state.c index 010abe5..a1c5d3c 100644 --- a/src/state.c +++ b/src/state.c @@ -378,10 +378,11 @@ add_features(const LV2_Feature* const* features, return ret; } +/// Return the canonical path for a directory with a trailing separator static char* -absolute_dir(const char* path) +real_dir(const char* path) { - char* abs_path = lilv_path_absolute(path); + char* abs_path = lilv_path_canonical(path); char* base = lilv_path_join(abs_path, NULL); free(abs_path); return base; @@ -425,10 +426,10 @@ lilv_state_new_from_instance(const LilvPlugin* plugin, state->plugin_uri = lilv_node_duplicate(lilv_plugin_get_uri(plugin)); state->abs2rel = zix_tree_new(false, abs_cmp, NULL, path_rel_free); state->rel2abs = zix_tree_new(false, rel_cmp, NULL, NULL); - state->scratch_dir = scratch_dir ? absolute_dir(scratch_dir) : NULL; - state->copy_dir = copy_dir ? absolute_dir(copy_dir) : NULL; - state->link_dir = link_dir ? absolute_dir(link_dir) : NULL; - state->dir = save_dir ? absolute_dir(save_dir) : NULL; + state->scratch_dir = scratch_dir ? real_dir(scratch_dir) : NULL; + state->copy_dir = copy_dir ? real_dir(copy_dir) : NULL; + state->link_dir = link_dir ? real_dir(link_dir) : NULL; + state->dir = save_dir ? real_dir(save_dir) : NULL; state->atom_Path = map->map(map->handle, LV2_ATOM__Path); LV2_State_Map_Path pmap = { state, abstract_path, absolute_path }; @@ -1189,7 +1190,7 @@ lilv_state_save(LilvWorld* world, return 1; } - char* abs_dir = absolute_dir(dir); + char* abs_dir = real_dir(dir); char* const path = lilv_path_join(abs_dir, filename); FILE* fd = fopen(path, "w"); if (!fd) { |