summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-18 17:31:18 +0100
committerDavid Robillard <d@drobilla.net>2020-12-18 17:39:09 +0100
commita3f425d6d2f70d31f614187453e47252bce9fc7e (patch)
treebea610c9fafc0943dd3b9776b3d4eb0809bc1dda
parent840392eb0d7b7b81cc75955d113fe71d9684fda2 (diff)
downloadlilv-a3f425d6d2f70d31f614187453e47252bce9fc7e.tar.gz
lilv-a3f425d6d2f70d31f614187453e47252bce9fc7e.tar.bz2
lilv-a3f425d6d2f70d31f614187453e47252bce9fc7e.zip
Windows: Fix saving state with files
-rw-r--r--NEWS3
-rw-r--r--src/state.c30
2 files changed, 22 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index d212a74..5c0c7d0 100644
--- a/NEWS
+++ b/NEWS
@@ -2,10 +2,11 @@ lilv (0.24.11) unstable;
* Allow connecting ports to structures in Python
* Fix potential memory error when joining filesystem paths
+ * Fix saving state with files on Windows
* Fix unlikely undefined behavior when saving state
* Fix writing state manifests on Windows
- -- David Robillard <d@drobilla.net> Thu, 17 Dec 2020 22:05:55 +0000
+ -- David Robillard <d@drobilla.net> Fri, 18 Dec 2020 16:30:48 +0000
lilv (0.24.10) stable;
diff --git a/src/state.c b/src/state.c
index 97709d3..fed7b18 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1152,16 +1152,14 @@ lilv_state_make_links(const LilvState* state, const char* dir)
i = zix_tree_iter_next(i)) {
const PathMap* pm = (const PathMap*)zix_tree_get(i);
- char* path = lilv_path_join(dir, pm->rel);
+ char* path = lilv_path_absolute_child(pm->rel, dir);
if (lilv_path_is_child(pm->abs, state->copy_dir)
&& strcmp(state->copy_dir, dir)) {
// Link directly to snapshot in the copy directory
- char* target = lilv_path_relative_to(pm->abs, dir);
- maybe_symlink(target, path);
- free(target);
+ maybe_symlink(pm->abs, path);
} else if (!lilv_path_is_child(pm->abs, dir)) {
const char* link_dir = state->link_dir ? state->link_dir : dir;
- char* pat = lilv_path_join(link_dir, pm->rel);
+ char* pat = lilv_path_absolute_child(pm->rel, link_dir);
if (!strcmp(dir, link_dir)) {
// Link directory is save directory, make link at exact path
remove(pat);
@@ -1180,7 +1178,7 @@ lilv_state_make_links(const LilvState* state, const char* dir)
// Make a link in the save directory to the external link
char* target = lilv_path_relative_to(lpath, dir);
- maybe_symlink(target, path);
+ maybe_symlink(lpath, path);
free(target);
free(lpath);
}
@@ -1288,6 +1286,16 @@ try_unlink(const char* state_dir, const char* path)
}
}
+static char*
+get_canonical_path(const LilvNode* const node)
+{
+ char* const path = lilv_node_get_path(node, NULL);
+ char* const real_path = lilv_path_canonical(path);
+
+ free(path);
+ return real_path;
+}
+
int
lilv_state_delete(LilvWorld* world,
const LilvState* state)
@@ -1299,7 +1307,7 @@ lilv_state_delete(LilvWorld* world,
LilvNode* bundle = lilv_new_file_uri(world, NULL, state->dir);
LilvNode* manifest = lilv_world_get_manifest_uri(world, bundle);
- char* manifest_path = lilv_node_get_path(manifest, NULL);
+ char* manifest_path = get_canonical_path(manifest);
const bool has_manifest = lilv_path_exists(manifest_path);
SordModel* model = sord_new(world->world, SORD_SPO, false);
@@ -1317,11 +1325,13 @@ lilv_state_delete(LilvWorld* world,
model, state->uri->node, world->uris.rdfs_seeAlso, NULL, NULL);
if (file) {
// Remove state file
- const uint8_t* uri = sord_node_get_string(file);
- char* path = (char*)serd_file_uri_parse(uri, NULL);
+ const uint8_t* uri = sord_node_get_string(file);
+ char* path = (char*)serd_file_uri_parse(uri, NULL);
+ char* real_path = lilv_path_canonical(path);
if (path) {
- try_unlink(state->dir, path);
+ try_unlink(state->dir, real_path);
}
+ serd_free(real_path);
serd_free(path);
}