Merge pull request #11002 from keszybz/path_join-merging
Path join merging
This commit is contained in:
@@ -781,7 +781,7 @@ int main(int argc, char *argv[]) {
|
||||
return log_tests_skipped("cgroupfs not available");
|
||||
|
||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||
test_execute_path = path_join(NULL, get_testdata_dir(), "test-execute");
|
||||
test_execute_path = path_join(get_testdata_dir(), "test-execute");
|
||||
assert_se(set_unit_path(test_execute_path) >= 0);
|
||||
|
||||
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
|
||||
|
||||
@@ -25,7 +25,7 @@ static void test_basic_parsing(void) {
|
||||
_cleanup_free_ char *journal_data_path = NULL;
|
||||
int r;
|
||||
|
||||
journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-1.txt");
|
||||
journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-1.txt");
|
||||
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
|
||||
assert_se(imp.fd >= 0);
|
||||
|
||||
@@ -56,7 +56,7 @@ static void test_bad_input(void) {
|
||||
_cleanup_free_ char *journal_data_path = NULL;
|
||||
int r;
|
||||
|
||||
journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-2.txt");
|
||||
journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-2.txt");
|
||||
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
|
||||
assert_se(imp.fd >= 0);
|
||||
|
||||
|
||||
@@ -123,9 +123,9 @@ static void test_path_is_mount_point(void) {
|
||||
|
||||
/* file mountpoints */
|
||||
assert_se(mkdtemp(tmp_dir) != NULL);
|
||||
file1 = path_join(NULL, tmp_dir, "file1");
|
||||
file1 = path_join(tmp_dir, "file1");
|
||||
assert_se(file1);
|
||||
file2 = path_join(NULL, tmp_dir, "file2");
|
||||
file2 = path_join(tmp_dir, "file2");
|
||||
assert_se(file2);
|
||||
fd = open(file1, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
|
||||
assert_se(fd > 0);
|
||||
@@ -133,10 +133,10 @@ static void test_path_is_mount_point(void) {
|
||||
fd = open(file2, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
|
||||
assert_se(fd > 0);
|
||||
close(fd);
|
||||
link1 = path_join(NULL, tmp_dir, "link1");
|
||||
link1 = path_join(tmp_dir, "link1");
|
||||
assert_se(link1);
|
||||
assert_se(symlink("file1", link1) == 0);
|
||||
link2 = path_join(NULL, tmp_dir, "link2");
|
||||
link2 = path_join(tmp_dir, "link2");
|
||||
assert_se(link1);
|
||||
assert_se(symlink("file2", link2) == 0);
|
||||
|
||||
@@ -146,16 +146,16 @@ static void test_path_is_mount_point(void) {
|
||||
assert_se(path_is_mount_point(link1, NULL, 0) == 0);
|
||||
|
||||
/* directory mountpoints */
|
||||
dir1 = path_join(NULL, tmp_dir, "dir1");
|
||||
dir1 = path_join(tmp_dir, "dir1");
|
||||
assert_se(dir1);
|
||||
assert_se(mkdir(dir1, 0755) == 0);
|
||||
dirlink1 = path_join(NULL, tmp_dir, "dirlink1");
|
||||
dirlink1 = path_join(tmp_dir, "dirlink1");
|
||||
assert_se(dirlink1);
|
||||
assert_se(symlink("dir1", dirlink1) == 0);
|
||||
dirlink1file = path_join(NULL, tmp_dir, "dirlink1file");
|
||||
dirlink1file = path_join(tmp_dir, "dirlink1file");
|
||||
assert_se(dirlink1file);
|
||||
assert_se(symlink("dirlink1/file", dirlink1file) == 0);
|
||||
dir2 = path_join(NULL, tmp_dir, "dir2");
|
||||
dir2 = path_join(tmp_dir, "dir2");
|
||||
assert_se(dir2);
|
||||
assert_se(mkdir(dir2, 0755) == 0);
|
||||
|
||||
@@ -165,7 +165,7 @@ static void test_path_is_mount_point(void) {
|
||||
assert_se(path_is_mount_point(dirlink1, NULL, 0) == 0);
|
||||
|
||||
/* file in subdirectory mountpoints */
|
||||
dir1file = path_join(NULL, dir1, "file");
|
||||
dir1file = path_join(dir1, "file");
|
||||
assert_se(dir1file);
|
||||
fd = open(dir1file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
|
||||
assert_se(fd > 0);
|
||||
@@ -206,7 +206,7 @@ static void test_path_is_mount_point(void) {
|
||||
assert_se(rlt == 1);
|
||||
|
||||
/* dirs */
|
||||
dir2file = path_join(NULL, dir2, "file");
|
||||
dir2file = path_join(dir2, "file");
|
||||
assert_se(dir2file);
|
||||
fd = open(dir2file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
|
||||
assert_se(fd > 0);
|
||||
|
||||
+36
-50
@@ -232,23 +232,47 @@ static void test_prefixes(void) {
|
||||
|
||||
static void test_path_join(void) {
|
||||
|
||||
#define test_join(root, path, rest, expected) { \
|
||||
#define test_join(expected, ...) { \
|
||||
_cleanup_free_ char *z = NULL; \
|
||||
z = path_join(root, path, rest); \
|
||||
z = path_join(__VA_ARGS__); \
|
||||
log_debug("got \"%s\", expected \"%s\"", z, expected); \
|
||||
assert_se(streq(z, expected)); \
|
||||
}
|
||||
|
||||
test_join("/root", "/a/b", "/c", "/root/a/b/c");
|
||||
test_join("/root", "a/b", "c", "/root/a/b/c");
|
||||
test_join("/root", "/a/b", "c", "/root/a/b/c");
|
||||
test_join("/root", "/", "c", "/root/c");
|
||||
test_join("/root", "/", NULL, "/root/");
|
||||
test_join("/root/a/b/c", "/root", "/a/b", "/c");
|
||||
test_join("/root/a/b/c", "/root", "a/b", "c");
|
||||
test_join("/root/a/b/c", "/root", "/a/b", "c");
|
||||
test_join("/root/c", "/root", "/", "c");
|
||||
test_join("/root/", "/root", "/", NULL);
|
||||
|
||||
test_join(NULL, "/a/b", "/c", "/a/b/c");
|
||||
test_join(NULL, "a/b", "c", "a/b/c");
|
||||
test_join(NULL, "/a/b", "c", "/a/b/c");
|
||||
test_join(NULL, "/", "c", "/c");
|
||||
test_join(NULL, "/", NULL, "/");
|
||||
test_join("/a/b/c", "", "/a/b", "/c");
|
||||
test_join("a/b/c", "", "a/b", "c");
|
||||
test_join("/a/b/c", "", "/a/b", "c");
|
||||
test_join("/c", "", "/", "c");
|
||||
test_join("/", "", "/", NULL);
|
||||
|
||||
test_join("/a/b/c", NULL, "/a/b", "/c");
|
||||
test_join("a/b/c", NULL, "a/b", "c");
|
||||
test_join("/a/b/c", NULL, "/a/b", "c");
|
||||
test_join("/c", NULL, "/", "c");
|
||||
test_join("/", NULL, "/", NULL);
|
||||
|
||||
test_join("", "", NULL);
|
||||
test_join("", NULL, "");
|
||||
test_join("", NULL, NULL);
|
||||
|
||||
test_join("foo/bar", "foo", "bar");
|
||||
test_join("foo/bar", "", "foo", "bar");
|
||||
test_join("foo/bar", NULL, "foo", NULL, "bar");
|
||||
test_join("foo/bar", "", "foo", "", "bar", "");
|
||||
test_join("foo/bar", "", "", "", "", "foo", "", "", "", "bar", "", "", "");
|
||||
|
||||
test_join("//foo///bar//", "", "/", "", "/foo/", "", "/", "", "/bar/", "", "/", "");
|
||||
test_join("/foo/bar/", "/", "foo", "/", "bar", "/");
|
||||
test_join("foo/bar/baz", "foo", "bar", "baz");
|
||||
test_join("foo/bar/baz", "foo/", "bar", "/baz");
|
||||
test_join("foo//bar//baz", "foo/", "/bar/", "/baz");
|
||||
test_join("//foo////bar////baz//", "//foo/", "///bar/", "///baz//");
|
||||
}
|
||||
|
||||
static void test_fsck_exists(void) {
|
||||
@@ -567,43 +591,6 @@ static void test_path_startswith_set(void) {
|
||||
assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "", "/zzz"), NULL));
|
||||
}
|
||||
|
||||
static void test_path_join_many(void) {
|
||||
char *j;
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("", NULL), ""));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("foo", NULL), "foo"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("foo", "bar"), "foo/bar"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("", "foo", "", "bar", ""), "foo/bar"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("", "", "", "", "foo", "", "", "", "bar", "", "", ""), "foo/bar"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("", "/", "", "/foo/", "", "/", "", "/bar/", "", "/", ""), "//foo///bar//"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("/", "foo", "/", "bar", "/"), "/foo/bar/"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("foo", "bar", "baz"), "foo/bar/baz"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("foo/", "bar", "/baz"), "foo/bar/baz"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("foo/", "/bar/", "/baz"), "foo//bar//baz"));
|
||||
free(j);
|
||||
|
||||
assert_se(streq_ptr(j = path_join_many("//foo/", "///bar/", "///baz//"), "//foo////bar////baz//"));
|
||||
free(j);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
@@ -625,7 +612,6 @@ int main(int argc, char **argv) {
|
||||
test_skip_dev_prefix();
|
||||
test_empty_or_root();
|
||||
test_path_startswith_set();
|
||||
test_path_join_many();
|
||||
|
||||
test_systemd_installation_has_version(argv[1]); /* NULL is OK */
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_path = path_join(NULL, get_testdata_dir(), "test-path");
|
||||
test_path = path_join(get_testdata_dir(), "test-path");
|
||||
assert_se(set_unit_path(test_path) >= 0);
|
||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ static void test_mount_points_list(const char *fname) {
|
||||
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
|
||||
|
||||
if (fname)
|
||||
fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname);
|
||||
fname = testdata_fname = path_join(get_testdata_dir(), fname);
|
||||
|
||||
LIST_HEAD_INIT(mp_list_head);
|
||||
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
|
||||
@@ -38,7 +38,7 @@ static void test_swap_list(const char *fname) {
|
||||
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
|
||||
|
||||
if (fname)
|
||||
fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname);
|
||||
fname = testdata_fname = path_join(get_testdata_dir(), fname);
|
||||
|
||||
LIST_HEAD_INIT(mp_list_head);
|
||||
assert_se(swap_list_get(fname, &mp_list_head) >= 0);
|
||||
|
||||
Reference in New Issue
Block a user