diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-04 02:53:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 02:53:59 +0900 |
commit | f482e22484229c22f06733530f3bb570d55bf367 (patch) | |
tree | 451cff09a0f803da63cfedf266ea30bc476a1983 /src/test | |
parent | ac76d1ec6986abc47a76c118b935a275a46dcaf4 (diff) | |
parent | acbab8697ed7402f7a7bd688531561e76f2e254b (diff) | |
download | systemd-f482e22484229c22f06733530f3bb570d55bf367.tar.gz |
Merge pull request #26653 from poettering/tmpfile-linkable-replace
teach link_tmpfile() to optionally replace files
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-tmpfiles.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c index 83d11f5cf6..0a856200c7 100644 --- a/src/test/test-tmpfiles.c +++ b/src/test/test-tmpfiles.c @@ -52,12 +52,28 @@ TEST(tmpfiles) { assert_se(write(fd, "foobar\n", 7) == 7); assert_se(touch(d) >= 0); - assert_se(link_tmpfile(fd, tmp, d) == -EEXIST); + assert_se(link_tmpfile(fd, tmp, d, /* replace= */ false) == -EEXIST); assert_se(unlink(d) >= 0); - assert_se(link_tmpfile(fd, tmp, d) >= 0); + assert_se(link_tmpfile(fd, tmp, d, /* replace= */ false) >= 0); assert_se(read_one_line_file(d, &line) >= 0); assert_se(streq(line, "foobar")); + + fd = safe_close(fd); + tmp = mfree(tmp); + + fd = open_tmpfile_linkable(d, O_RDWR|O_CLOEXEC, &tmp); + assert_se(fd >= 0); + + assert_se(write(fd, "waumiau\n", 8) == 8); + + assert_se(link_tmpfile(fd, tmp, d, /* replace= */ false) == -EEXIST); + assert_se(link_tmpfile(fd, tmp, d, /* replace= */ true) >= 0); + + line = mfree(line); + assert_se(read_one_line_file(d, &line) >= 0); + assert_se(streq(line, "waumiau")); + assert_se(unlink(d) >= 0); } |