summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-11-12 17:54:28 -0500
committerDavid Robillard <d@drobilla.net>2022-11-16 10:22:55 -0500
commit94b3980bcbe40bca8f361eb63a87f371337d067c (patch)
tree7971eae1dfa77028af60f8e071f0eef42d3dc877
parent072e460e00cc0460a3385d73f266262956cd3014 (diff)
downloadlilv-94b3980bcbe40bca8f361eb63a87f371337d067c.tar.gz
lilv-94b3980bcbe40bca8f361eb63a87f371337d067c.tar.bz2
lilv-94b3980bcbe40bca8f361eb63a87f371337d067c.zip
Use zix_create_symlink()
-rw-r--r--src/filesystem.c18
-rw-r--r--src/filesystem.h8
-rw-r--r--src/state.c36
3 files changed, 25 insertions, 37 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index e2fc776..572b8ea 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -172,24 +172,6 @@ lilv_is_directory(const char* path)
#endif
}
-int
-lilv_symlink(const char* oldpath, const char* newpath)
-{
- int ret = 0;
- if (strcmp(oldpath, newpath)) {
-#ifdef _WIN32
- ret = !CreateHardLink(newpath, oldpath, 0);
-#else
- char* target = lilv_path_relative_to(oldpath, newpath);
-
- ret = symlink(target, newpath);
-
- free(target);
-#endif
- }
- return ret;
-}
-
void
lilv_dir_for_each(const char* path,
void* data,
diff --git a/src/filesystem.h b/src/filesystem.h
index 849d78f..db6114e 100644
--- a/src/filesystem.h
+++ b/src/filesystem.h
@@ -42,14 +42,6 @@ bool
lilv_is_directory(const char* path);
/**
- Create a symlink at `newpath` that points to `oldpath`.
-
- @return Zero on success, otherwise non-zero and `errno` is set.
-*/
-int
-lilv_symlink(const char* oldpath, const char* newpath);
-
-/**
Visit every file in the directory at `path`.
@param path A path to a directory.
diff --git a/src/state.c b/src/state.c
index ba2df78..571a591 100644
--- a/src/state.c
+++ b/src/state.c
@@ -12,6 +12,7 @@
#include "zix/filesystem.h"
#include "zix/path.h"
#include "zix/status.h"
+#include "zix/string_view.h"
#include "zix/tree.h"
#include "lv2/atom/atom.h"
@@ -1018,22 +1019,34 @@ link_exists(const char* path, const void* data)
return !matches;
}
-static int
-maybe_symlink(const char* oldpath, const char* newpath)
+static ZixStatus
+create_link(const char* oldpath, const char* newpath)
{
- if (link_exists(newpath, oldpath)) {
- return 0;
- }
+ const ZixStringView parent_path = zix_path_parent_path(newpath);
+ char* const parent = zix_string_view_copy(NULL, parent_path);
- const int st = lilv_symlink(oldpath, newpath);
- if (st) {
- LILV_ERRORF(
- "Failed to link %s => %s (%s)\n", newpath, oldpath, strerror(errno));
+ char* const relpath = zix_path_lexically_relative(NULL, oldpath, parent);
+
+ ZixStatus st = ZIX_STATUS_SUCCESS;
+ if ((st = zix_create_symlink(relpath, newpath))) {
+ if ((st = zix_create_hard_link(oldpath, newpath))) {
+ LILV_ERRORF(
+ "Failed to link %s => %s (%s)\n", newpath, oldpath, zix_strerror(st));
+ }
}
+ zix_free(NULL, relpath);
+ zix_free(NULL, parent);
return st;
}
+static ZixStatus
+maybe_symlink(const char* oldpath, const char* newpath)
+{
+ return link_exists(newpath, oldpath) ? ZIX_STATUS_SUCCESS
+ : create_link(oldpath, newpath);
+}
+
static void
write_property_array(const LilvState* state,
const PropertyArray* array,
@@ -1197,11 +1210,12 @@ lilv_state_make_links(const LilvState* state, const char* dir)
// Make a link in the link directory to external file
char* lpath = lilv_find_free_path(pat, link_exists, pm->abs);
if (zix_file_type(lpath) == ZIX_FILE_TYPE_NONE) {
- if (lilv_symlink(pm->abs, lpath)) {
+ const ZixStatus st = create_link(pm->abs, lpath);
+ if (st) {
LILV_ERRORF("Failed to link %s => %s (%s)\n",
pm->abs,
lpath,
- strerror(errno));
+ zix_strerror(st));
}
}