X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-copy.c;h=b3dfedd36c98c77f308319e28a8197466d313073;hb=7cc655f99a364e6762a50ce25864979b3a52a73f;hp=b893c49963738c27571fcd86e0a47b91d307254c;hpb=3f4a243f747c3397900038d2ca2b7645614935a5;p=elogind.git diff --git a/src/test/test-copy.c b/src/test/test-copy.c index b893c4996..b3dfedd36 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -1,7 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -/*** - Copyright © 2014 Ronny Chevalier -***/ #include @@ -240,7 +237,26 @@ 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(); @@ -254,6 +270,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; }