summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-06-05 16:52:22 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit3f87ae2530d8bb022f54526c3a568165a34acf05 (patch)
treef405abf1d38e45e2a10d40aa352bdc18ca19e51d /src/test
parent0d77192b13d5fa28456d0d1bea6c63458fd66cb3 (diff)
copy: rework copy_file_atomic() to copy the specified file via O_TMPFILE if possible
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-copy.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index 0d39d41bb..9dc0ddf95 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -242,7 +242,27 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
unlink(fn3);
}
+static void test_copy_atomic(void) {
+ _cleanup_(rm_rf_physical_and_freep) char *p = NULL;
+ const char *q;
+ int r;
+
+ assert_se(mkdtemp_malloc(NULL, &p) >= 0);
+
+ q = strjoina(p, "/fstab");
+
+ r = copy_file_atomic("/etc/fstab", q, 0644, 0, COPY_REFLINK);
+ if (r == -ENOENT)
+ return;
+
+ assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, COPY_REFLINK) == -EEXIST);
+
+ assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, COPY_REPLACE) >= 0);
+}
+
int main(int argc, char *argv[]) {
+ log_set_max_level(LOG_DEBUG);
+
#if 0 /// UNNEEDED by elogind
test_copy_file();
test_copy_file_fd();
@@ -255,6 +275,7 @@ int main(int argc, char *argv[]) {
test_copy_bytes_regular_file(argv[0], true, 1000);
test_copy_bytes_regular_file(argv[0], false, 32000); /* larger than copy buffer size */
test_copy_bytes_regular_file(argv[0], true, 32000);
+ test_copy_atomic();
return 0;
}