From a2bcfc37f3634179b4e75fff38d4c36a1ab2a812 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 6 Dec 2024 08:26:35 -0500 Subject: Fix listdir() * Now returns the absolute path(s) to the file(s) * Remove restriction on reading hidden files --- src/lib/core/utils.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index c03f8fa..aa4173c 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -766,7 +766,15 @@ struct StrList *listdir(const char *path) { if (!strcmp(rec->d_name, ".") || !strcmp(rec->d_name, "..")) { continue; } - strlist_append(&node, rec->d_name); + char *fullpath = join_ex("/", path, rec->d_name, NULL); + if (!fullpath) { + SYSERROR("%s", "Unable to allocate bytes to construct full path"); + guard_strlist_free(&node); + closedir(dp); + return NULL; + } + strlist_append(&node, fullpath); + guard_free(fullpath); } closedir(dp); return node; @@ -791,8 +799,6 @@ int mkdirs(const char *_path, mode_t mode) { char result[PATH_MAX] = {0}; int status = 0; while ((token = strsep(&path, "/")) != NULL && !status) { - if (token[0] == '.') - continue; strcat(result, token); strcat(result, "/"); status = mkdir(result, mode); -- cgit