From 67a33e70aa2b3f2f78742e773bac5ccb7be95c20 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Nov 2022 17:54:11 -0500 Subject: Use zix_file_type() and zix_symlink_type() --- src/filesystem.c | 12 ------------ src/filesystem.h | 4 ---- src/state.c | 15 ++++++++------- 3 files changed, 8 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/filesystem.c b/src/filesystem.c index 3c4cbbf..7897920 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -9,7 +9,6 @@ # include # include # include -# define F_OK 0 # define mkdir(path, flags) _mkdir(path) # define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) #else @@ -275,17 +274,6 @@ lilv_path_canonical(const char* path) #endif } -bool -lilv_path_exists(const char* path) -{ -#if USE_LSTAT - struct stat st; - return !lstat(path, &st); -#else - return !access(path, F_OK); -#endif -} - bool lilv_is_directory(const char* path) { diff --git a/src/filesystem.h b/src/filesystem.h index dfff4c9..424afc6 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -77,10 +77,6 @@ lilv_path_join(const char* a, const char* b); char* lilv_path_canonical(const char* path); -/// Return true iff `path` points to an existing file system entry -bool -lilv_path_exists(const char* path); - /// Return true iff `path` points to an existing directory bool lilv_is_directory(const char* path); diff --git a/src/state.c b/src/state.c index a4fa11c..d215c15 100644 --- a/src/state.c +++ b/src/state.c @@ -1,4 +1,4 @@ -// Copyright 2007-2019 David Robillard +// Copyright 2007-2022 David Robillard // SPDX-License-Identifier: ISC #include "filesystem.h" @@ -8,6 +8,7 @@ #include "serd/serd.h" #include "sord/sord.h" #include "sratom/sratom.h" +#include "zix/filesystem.h" #include "zix/tree.h" #include "lv2/atom/atom.h" @@ -235,7 +236,7 @@ path_exists(const char* path, const void* ignored) { (void)ignored; - return lilv_path_exists(path); + return zix_file_type(path) != ZIX_FILE_TYPE_NONE; } static bool @@ -913,7 +914,7 @@ add_state_to_manifest(LilvWorld* lworld, SerdEnv* env = serd_env_new(&manifest); SordModel* model = sord_new(world, SORD_SPO, false); - if (lilv_path_exists(manifest_path)) { + if (zix_file_type(manifest_path) == ZIX_FILE_TYPE_REGULAR) { // Read manifest into model SerdReader* reader = sord_new_reader(model, env, SERD_TURTLE, NULL); SerdStatus st = serd_reader_read_file(reader, manifest.buf); @@ -997,7 +998,7 @@ static bool link_exists(const char* path, const void* data) { const char* target = (const char*)data; - if (!lilv_path_exists(path)) { + if (zix_file_type(path) == ZIX_FILE_TYPE_NONE) { return false; } char* real_path = lilv_path_canonical(path); @@ -1183,7 +1184,7 @@ 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)) { + if (zix_file_type(lpath) == ZIX_FILE_TYPE_NONE) { if (lilv_symlink(pm->abs, lpath)) { LILV_ERRORF("Failed to link %s => %s (%s)\n", pm->abs, @@ -1295,7 +1296,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) && lilv_remove(path)) { + if (zix_file_type(path) != ZIX_FILE_TYPE_NONE && lilv_remove(path)) { LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno)); } } @@ -1322,7 +1323,7 @@ lilv_state_delete(LilvWorld* world, const LilvState* state) LilvNode* bundle = lilv_new_file_uri(world, NULL, state->dir); LilvNode* manifest = lilv_world_get_manifest_uri(world, bundle); char* manifest_path = get_canonical_path(manifest); - const bool has_manifest = lilv_path_exists(manifest_path); + const bool has_manifest = zix_file_type(manifest_path) != ZIX_FILE_TYPE_NONE; SordModel* model = sord_new(world->world, SORD_SPO, false); if (has_manifest) { -- cgit v1.2.1