Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions libutils/glob_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/glob_lib_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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 *);
Expand Down Expand Up @@ -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));
Expand All @@ -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));

Expand Down Expand Up @@ -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));
Expand Down
Loading