diff --git a/libutils/glob_lib.c b/libutils/glob_lib.c index 1c057d82..05a5dab0 100644 --- a/libutils/glob_lib.c +++ b/libutils/glob_lib.c @@ -432,7 +432,9 @@ static void PathWalkCallback( { /* We have matched each and every part of the glob pattern, thus we * have a full match. */ - char *const match = xstrdup(dirpath); + char *match; + xasprintf(&match, "%s" FILE_SEPARATOR_STR, dirpath); + SeqAppend(data->matches, match); Log(LOG_LEVEL_DEBUG, "Full match! Directory '%s' has matched all previous sub patterns", @@ -679,7 +681,10 @@ StringSet *GlobFileList(const char *pattern) { for (size_t j = 0; j < globbuf.gl_pathc; j++) { - StringSetAdd(set, SafeStringDuplicate(globbuf.gl_pathv[j])); + char *path = IsDirReal(globbuf.gl_pathv[j]) + ? StringFormat("%s" FILE_SEPARATOR_STR, globbuf.gl_pathv[j]) + : SafeStringDuplicate(globbuf.gl_pathv[j]); + StringSetAdd(set, path); } globfree(&globbuf); } diff --git a/tests/unit/glob_lib_test.c b/tests/unit/glob_lib_test.c index 5457bfcf..4dba2ce0 100644 --- a/tests/unit/glob_lib_test.c +++ b/tests/unit/glob_lib_test.c @@ -271,7 +271,7 @@ static void test_glob_find(void) { Seq *const matches = GlobFind("."); assert_int_equal(SeqLength(matches), 1); - assert_string_equal(SeqAt(matches, 0), "."); + assert_string_equal(SeqAt(matches, 0), "." FILE_SEPARATOR_STR); SeqDestroy(matches); } } @@ -289,10 +289,10 @@ static void test_glob_file_list(void) // Create test subdirectories. static const char *const test_subdirs[] = { - "foo", - "foo" FILE_SEPARATOR_STR "bar", - "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR "baz", - "qux", + "foo" FILE_SEPARATOR_STR, + "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR, + "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR "baz" FILE_SEPARATOR_STR, + "qux" FILE_SEPARATOR_STR, }; const size_t num_test_subdirs = sizeof(test_subdirs) / sizeof(const char *); @@ -471,14 +471,14 @@ static void test_glob_file_list(void) matches = GlobFileList(pattern); assert_int_equal(StringSetSize(matches), 4); - ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo", test_dir); + ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); ret = snprintf( path, PATH_MAX, - "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar", + "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); @@ -487,12 +487,12 @@ static void test_glob_file_list(void) path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR - "bar" FILE_SEPARATOR_STR "baz", + "bar" FILE_SEPARATOR_STR "baz" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); - ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "qux", test_dir); + ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "qux" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); @@ -676,14 +676,14 @@ static void test_glob_file_list(void) assert_int_equal(StringSetSize(matches), 2); - ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo", test_dir); + ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); ret = snprintf( path, PATH_MAX, - "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar", + "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path));