From dd521d78d1959d694e6e5a565a37e9693756cb00 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 4 Aug 2020 15:59:29 +0200 Subject: Separate filesystem utilities --- src/state.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c index e4e381a..749316c 100644 --- a/src/state.c +++ b/src/state.c @@ -14,6 +14,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "filesystem.h" #include "lilv_internal.h" #include "lilv/lilv.h" @@ -227,6 +228,12 @@ retrieve_callback(LV2_State_Handle handle, return NULL; } +static bool +path_exists(const char* path, const void* ignored) +{ + return lilv_path_exists(path); +} + static bool lilv_state_has_path(const char* path, const void* state) { @@ -277,7 +284,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, if (!copy || !lilv_file_equals(real_path, copy)) { // No recent enough copy, make a new one free(copy); - copy = lilv_find_free_path(cpath, lilv_path_exists, NULL); + copy = lilv_find_free_path(cpath, path_exists, NULL); if ((st = lilv_copy_file(real_path, copy))) { LILV_ERRORF("Error copying state file %s (%s)\n", copy, strerror(st)); @@ -956,7 +963,7 @@ static bool link_exists(const char* path, const void* data) { const char* target = (const char*)data; - if (!lilv_path_exists(path, NULL)) { + if (!lilv_path_exists(path)) { return false; } char* real_path = lilv_realpath(path); @@ -968,7 +975,19 @@ link_exists(const char* path, const void* data) static int maybe_symlink(const char* oldpath, const char* newpath) { - return link_exists(newpath, oldpath) ? 0 : lilv_symlink(oldpath, newpath); + if (link_exists(newpath, oldpath)) { + return 0; + } + + const int st = lilv_symlink(oldpath, newpath); + if (st) { + LILV_ERRORF("Failed to link %s => %s (%s)\n", + newpath, + oldpath, + strerror(errno)); + } + + return st; } static void @@ -1125,8 +1144,13 @@ lilv_state_make_links(const LilvState* state, const char* dir) } else { // Make a link in the link directory to external file char* lpath = lilv_find_free_path(pat, link_exists, pm->abs); - if (!lilv_path_exists(lpath, NULL)) { - lilv_symlink(pm->abs, lpath); + if (!lilv_path_exists(lpath)) { + if (lilv_symlink(pm->abs, lpath)) { + LILV_ERRORF("Failed to link %s => %s (%s)\n", + pm->abs, + lpath, + strerror(errno)); + } } // Make a link in the save directory to the external link @@ -1228,7 +1252,7 @@ static void try_unlink(const char* state_dir, const char* path) { if (!strncmp(state_dir, path, strlen(state_dir))) { - if (lilv_path_exists(path, NULL) && unlink(path)) { + if (lilv_path_exists(path) && unlink(path)) { LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno)); } } @@ -1246,7 +1270,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); - const bool has_manifest = lilv_path_exists(manifest_path, NULL); + const bool has_manifest = lilv_path_exists(manifest_path); SordModel* model = sord_new(world->world, SORD_SPO, false); if (has_manifest) { -- cgit v1.2.1