1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

test: add test for copying symlink with copy_tree_at()

This commit is contained in:
Yu Watanabe 2024-02-15 19:00:54 +09:00
parent d1553bfd20
commit 0f938a024e

View File

@ -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;