summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/filesystem.c4
-rw-r--r--test/test_filesystem.c14
2 files changed, 18 insertions, 0 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index e610d07..7cda4d9 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -272,6 +272,10 @@ lilv_copy_file(const char* src, const char* dst)
}
}
+ if (!st && fflush(out)) {
+ st = errno;
+ }
+
if (!st && (ferror(in) || ferror(out))) {
st = EBADF;
}
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index 20faa2a..8c7b1ba 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -21,6 +21,7 @@
#include "../src/filesystem.h"
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -272,6 +273,19 @@ test_copy_file(void)
assert(!lilv_copy_file(file_path, copy_path));
assert(lilv_file_equals(file_path, copy_path));
+ if (lilv_path_exists("/dev/full")) {
+ // 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(!lilv_remove(copy_path));
assert(!lilv_remove(file_path));
assert(!lilv_remove(temp_dir));