From: Daan De Meyer Date: Mon, 5 Dec 2022 10:15:58 +0000 (+0100) Subject: test-fs-util: Add relative path chase_symlinks() tests X-Git-Tag: v253-rc1~355 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94799c305acad138ce62e562318fbe7936a50dce;p=thirdparty%2Fsystemd.git test-fs-util: Add relative path chase_symlinks() tests --- diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 4bf0a5daf87..8c4b632ed03 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/..");