diff options
author | David Robillard <d@drobilla.net> | 2020-01-18 15:23:29 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-01-18 15:32:59 +0100 |
commit | c9a54e019d54cbccfff742d5c5662ff021b187a9 (patch) | |
tree | e3da9c0a6fd8fce79e0f31bfdc6bf4e72ee1d1fe | |
parent | d186359c86185453692871b33d9c73adabf47eb6 (diff) | |
download | lilv-c9a54e019d54cbccfff742d5c5662ff021b187a9.tar.gz lilv-c9a54e019d54cbccfff742d5c5662ff021b187a9.tar.bz2 lilv-c9a54e019d54cbccfff742d5c5662ff021b187a9.zip |
Only remove files in state bundle when deleting state
-rw-r--r-- | src/state.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/state.c b/src/state.c index 5db529c..5c3b90c 100644 --- a/src/state.c +++ b/src/state.c @@ -1220,10 +1220,12 @@ lilv_state_to_string(LilvWorld* world, } static void -try_unlink(const char* path) +try_unlink(const char* state_dir, const char* path) { - if (unlink(path)) { - LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno)); + if (!strncmp(state_dir, path, strlen(state_dir))) { + if (lilv_path_exists(path, NULL) && unlink(path)) { + LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno)); + } } } @@ -1256,7 +1258,7 @@ lilv_state_delete(LilvWorld* world, // Remove state file char* path = (char*)serd_file_uri_parse(sord_node_get_string(file), NULL); - try_unlink(path); + try_unlink(state->dir, path); serd_free(path); } @@ -1271,7 +1273,7 @@ lilv_state_delete(LilvWorld* world, if (sord_num_quads(model) == 0) { // Manifest is empty, attempt to remove bundle entirely - try_unlink(manifest_path); + try_unlink(state->dir, manifest_path); // Remove all known files from state bundle for (ZixTreeIter* i = zix_tree_begin(state->abs2rel); @@ -1279,7 +1281,7 @@ lilv_state_delete(LilvWorld* world, 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); + try_unlink(state->dir, path); free(path); } |