From: Yu Watanabe Date: Thu, 15 Feb 2024 10:00:54 +0000 (+0900) Subject: test: add test for copying symlink with copy_tree_at() X-Git-Tag: v256-rc1~843^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f938a024e2118e10520fa83ec9f7a3fc14b4856;p=thirdparty%2Fsystemd.git test: add test for copying symlink with copy_tree_at() --- diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 61bfbc0c421..41c7884825b 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -253,6 +253,43 @@ TEST(copy_tree) { (void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL); } +TEST(copy_tree_at_symlink) { + _cleanup_(rm_rf_physical_and_freep) char *t = NULL; + _cleanup_close_ int tfd = -EBADF, fd = -EBADF; + _cleanup_free_ char *p = NULL, *q = NULL; + const char *expect = "hgoehogefoobar"; + + tfd = mkdtemp_open(NULL, O_PATH, &t); + assert_se(tfd >= 0); + + assert_se(symlinkat(expect, tfd, "from") >= 0); + + assert_se(copy_tree_at(tfd, "from", tfd, "to_1", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0); + assert_se(readlinkat_malloc(tfd, "to_1", &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + + assert_se(q = path_join(t, "from")); + assert_se(copy_tree_at(AT_FDCWD, q, tfd, "to_2", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0); + assert_se(readlinkat_malloc(tfd, "to_2", &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + q = mfree(q); + + fd = openat(tfd, "from", O_CLOEXEC | O_PATH | O_NOFOLLOW); + assert_se(fd >= 0); + assert_se(copy_tree_at(fd, NULL, tfd, "to_3", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0); + assert_se(readlinkat_malloc(tfd, "to_3", &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + + assert_se(copy_tree_at(fd, "", tfd, "to_4", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0); + assert_se(readlinkat_malloc(tfd, "to_4", &p) >= 0); + assert_se(streq(p, expect)); + p = mfree(p); + fd = safe_close(fd); +} + TEST(copy_bytes) { _cleanup_close_pair_ int pipefd[2] = EBADF_PAIR; _cleanup_close_ int infd = -EBADF;