summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-09-16 11:43:54 +0200
committerDavid Robillard <d@drobilla.net>2018-09-16 11:54:06 +0200
commit3a7cdabd7a0782774dc4c8c06d81ee76e317512a (patch)
tree44b42d02304531e9a3464ad5d60cd7e90ece24a1 /src
parented6fcc2cc5e7eea807ff41ffb3e98430300a0b6b (diff)
downloadlilv-3a7cdabd7a0782774dc4c8c06d81ee76e317512a.tar.gz
lilv-3a7cdabd7a0782774dc4c8c06d81ee76e317512a.tar.bz2
lilv-3a7cdabd7a0782774dc4c8c06d81ee76e317512a.zip
Fix lilv_state_delete() for state bundles with extra files
Diffstat (limited to 'src')
-rw-r--r--src/state.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/state.c b/src/state.c
index 4cd0ccb..0b14f25 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1146,6 +1146,14 @@ lilv_state_to_string(LilvWorld* world,
return (char*)serd_chunk_sink_finish(&chunk);
}
+static void
+try_unlink(const char* path)
+{
+ if (unlink(path)) {
+ LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno));
+ }
+}
+
LILV_API int
lilv_state_delete(LilvWorld* world,
const LilvState* state)
@@ -1175,9 +1183,7 @@ lilv_state_delete(LilvWorld* world,
// Remove state file
char* path = lilv_file_uri_parse(
(const char*)sord_node_get_string(file), NULL);
- if (unlink(path)) {
- LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno));
- }
+ try_unlink(path);
lilv_free(path);
}
@@ -1192,16 +1198,22 @@ lilv_state_delete(LilvWorld* world,
if (sord_num_quads(model) == 0) {
// Manifest is empty, attempt to remove bundle entirely
- if (unlink(manifest_path)) {
- LILV_ERRORF("Failed to remove %s (%s)\n",
- manifest_path, strerror(errno));
+ try_unlink(manifest_path);
+
+ // Remove all known files from state bundle
+ for (ZixTreeIter* i = zix_tree_begin(state->abs2rel);
+ i != zix_tree_end(state->abs2rel);
+ i = zix_tree_iter_next(i)) {
+ const PathMap* pm = (const PathMap*)zix_tree_get(i);
+ char* path = lilv_path_join(state->dir, pm->rel);
+ try_unlink(path);
+ free(path);
}
- char* dir_path = lilv_file_uri_parse(state->dir, NULL);
- if (rmdir(dir_path)) {
- LILV_ERRORF("Failed to remove %s (%s)\n",
- dir_path, strerror(errno));
+
+ if (rmdir(state->dir)) {
+ LILV_ERRORF("Failed to remove directory %s (%s)\n",
+ state->dir, strerror(errno));
}
- lilv_free(dir_path);
} else {
// Still something in the manifest, reload bundle
lilv_world_load_bundle(world, bundle);