From 1bb1de7ecd19a99a1a29a9a4d734fcc38c2ba9cc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 18 Jan 2020 15:28:45 +0100 Subject: Fix deleting state bundles loaded from the model --- src/state.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c index 5c3b90c..7e0f50d 100644 --- a/src/state.c +++ b/src/state.c @@ -1276,13 +1276,24 @@ lilv_state_delete(LilvWorld* world, try_unlink(state->dir, 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(state->dir, path); - free(path); + if (state->abs2rel) { + // State created from instance, get paths from map + 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(state->dir, path); + free(path); + } + } else { + // State loaded from model, get paths from loaded properties + for (uint32_t i = 0; i < state->props.n; ++i) { + const Property* const p = &state->props.props[i]; + if (p->type == state->atom_Path) { + try_unlink(state->dir, (const char*)p->value); + } + } } if (rmdir(state->dir)) { -- cgit v1.2.1