summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-12-05 11:15:58 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-07 10:39:20 +0900
commit94799c305acad138ce62e562318fbe7936a50dce (patch)
tree0a2c32a88b64f77a4fa311118ba4572541eabfd4
parentcc420ae52a2954bde45cc501139ba853b50f5517 (diff)
downloadsystemd-94799c305acad138ce62e562318fbe7936a50dce.tar.gz
test-fs-util: Add relative path chase_symlinks() tests
-rw-r--r--src/test/test-fs-util.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 4bf0a5daf8..8c4b632ed0 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -27,7 +27,7 @@
static const char *arg_test_dir = NULL;
TEST(chase_symlinks) {
- _cleanup_free_ char *result = NULL;
+ _cleanup_free_ char *result = NULL, *pwd = NULL;
_cleanup_close_ int pfd = -1;
char *temp;
const char *top, *p, *pslash, *q, *qslash;
@@ -245,6 +245,30 @@ TEST(chase_symlinks) {
assert_se(path_equal(result, p));
result = mfree(result);
+ /* Relative paths */
+
+ assert_se(safe_getcwd(&pwd) >= 0);
+
+ assert_se(chdir(temp) >= 0);
+
+ p = "this/is/a/relative/path";
+ r = chase_symlinks(p, NULL, CHASE_NONEXISTENT, &result, NULL);
+ assert_se(r == 0);
+
+ p = strjoina(temp, "/", p);
+ assert_se(path_equal(result, p));
+ result = mfree(result);
+
+ p = "this/is/a/relative/path";
+ r = chase_symlinks(p, temp, CHASE_NONEXISTENT, &result, NULL);
+ assert_se(r == 0);
+
+ p = strjoina(temp, "/", p);
+ assert_se(path_equal(result, p));
+ result = mfree(result);
+
+ assert_se(chdir(pwd) >= 0);
+
/* Path which doesn't exist, but contains weird stuff */
p = strjoina(temp, "/idontexist/..");