summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-11-12 17:54:22 -0500
committerDavid Robillard <d@drobilla.net>2022-11-16 10:22:55 -0500
commita2d40769d25c9495edce67be67be0ac36491ce80 (patch)
tree05eaa386cb4cfc8fb0531e940153bf3816994824
parent31da12734905888bb13f0ee832b62d39f2d52eb6 (diff)
downloadlilv-a2d40769d25c9495edce67be67be0ac36491ce80.tar.gz
lilv-a2d40769d25c9495edce67be67be0ac36491ce80.tar.bz2
lilv-a2d40769d25c9495edce67be67be0ac36491ce80.zip
Use zix_copy_file()
-rw-r--r--src/filesystem.c44
-rw-r--r--src/filesystem.h8
-rw-r--r--src/state.c8
-rw-r--r--test/test_filesystem.c38
-rw-r--r--test/test_util.c4
5 files changed, 4 insertions, 98 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index c0ad864..7e42dbd 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -25,16 +25,11 @@
#include <sys/stat.h>
-#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifndef PAGE_SIZE
-# define PAGE_SIZE 4096
-#endif
-
static bool
lilv_is_dir_sep(const char c)
{
@@ -198,45 +193,6 @@ lilv_is_directory(const char* path)
}
int
-lilv_copy_file(const char* src, const char* dst)
-{
- FILE* in = fopen(src, "r");
- if (!in) {
- return errno;
- }
-
- FILE* out = fopen(dst, "w");
- if (!out) {
- fclose(in);
- return errno;
- }
-
- char* page = (char*)malloc(PAGE_SIZE);
- size_t n_read = 0;
- int st = 0;
- while ((n_read = fread(page, 1, PAGE_SIZE, in)) > 0) {
- if (fwrite(page, 1, n_read, out) != n_read) {
- st = errno;
- break;
- }
- }
-
- if (!st && fflush(out)) {
- st = errno;
- }
-
- if (!st && (ferror(in) || ferror(out))) {
- st = EBADF;
- }
-
- free(page);
- fclose(in);
- fclose(out);
-
- return st;
-}
-
-int
lilv_symlink(const char* oldpath, const char* newpath)
{
int ret = 0;
diff --git a/src/filesystem.h b/src/filesystem.h
index 4d66e19..33294da 100644
--- a/src/filesystem.h
+++ b/src/filesystem.h
@@ -47,14 +47,6 @@ bool
lilv_is_directory(const char* path);
/**
- Copy the file at path `src` to path `dst`.
-
- @return Zero on success, or a standard `errno` error code.
-*/
-int
-lilv_copy_file(const char* src, const char* dst);
-
-/**
Create a symlink at `newpath` that points to `oldpath`.
@return Zero on success, otherwise non-zero and `errno` is set.
diff --git a/src/state.c b/src/state.c
index bce4eaa..c0c9400 100644
--- a/src/state.c
+++ b/src/state.c
@@ -300,10 +300,10 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path)
if (!copy || !zix_file_equals(NULL, real_path, copy)) {
// No recent enough copy, make a new one
free(copy);
- copy = lilv_find_free_path(cpath, path_exists, NULL);
- int rc = 0;
- if ((rc = lilv_copy_file(real_path, copy))) {
- LILV_ERRORF("Error copying state file %s (%s)\n", copy, strerror(st));
+ copy = lilv_find_free_path(cpath, path_exists, NULL);
+ if ((st = zix_copy_file(NULL, real_path, copy, 0U))) {
+ LILV_ERRORF(
+ "Error copying state file %s (%s)\n", copy, zix_strerror(st));
}
}
zix_free(NULL, real_path);
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index 01ccd5d..021d66f 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -11,7 +11,6 @@
#include "zix/path.h"
#include <assert.h>
-#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -157,42 +156,6 @@ test_is_directory(void)
}
static void
-test_copy_file(void)
-{
- char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
- char* const copy_path = zix_path_join(NULL, temp_dir, "lilv_test_copy");
-
- FILE* f = fopen(file_path, "w");
- fprintf(f, "test\n");
- fclose(f);
-
- assert(!lilv_copy_file(file_path, copy_path));
- assert(zix_file_equals(NULL, file_path, copy_path));
-
- if (zix_file_type("/dev/full") != ZIX_FILE_TYPE_NONE) {
- // Copy short file (error after flushing)
- assert(lilv_copy_file(file_path, "/dev/full") == ENOSPC);
-
- // Copy long file (error during writing)
- f = fopen(file_path, "w");
- for (size_t i = 0; i < 4096; ++i) {
- fprintf(f, "test\n");
- }
- fclose(f);
- assert(lilv_copy_file(file_path, "/dev/full") == ENOSPC);
- }
-
- assert(!zix_remove(copy_path));
- assert(!zix_remove(file_path));
- assert(!zix_remove(temp_dir));
-
- free(copy_path);
- free(file_path);
- free(temp_dir);
-}
-
-static void
test_flock(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
@@ -275,7 +238,6 @@ main(void)
test_path_parent();
test_path_filename();
test_is_directory();
- test_copy_file();
test_flock();
test_dir_for_each();
diff --git a/test/test_util.c b/test/test_util.c
index f6f7feb..2e5b2fb 100644
--- a/test/test_util.c
+++ b/test/test_util.c
@@ -27,10 +27,6 @@ main(void)
fclose(fb);
fclose(fa);
- assert(lilv_copy_file("does/not/exist", "copy"));
- assert(lilv_copy_file(a_path, "not/a/dir/copy"));
- assert(!lilv_copy_file(a_path, "copy_c"));
-
assert(!zix_remove(a_path));
assert(!zix_remove(b_path));
assert(!zix_remove(dir));