kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 1fae25960362a33a639e7f405c38c533233c9b07
parent d6ab1d74450cbe17ea0e7b12d05d6bb827c6a783
Author: Joris Vink <joris@coders.se>
Date:   Tue,  7 Apr 2015 09:27:58 +0200

Use stat(2) to figure out type of directory entry.

readdir(2) might not be able to give back the correct
type in the d_type member and we should properly handle
the DT_UNKNOWN value anyway.

Fixes #39.

Diffstat:
src/cli.c | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/cli.c b/src/cli.c @@ -727,6 +727,7 @@ static void cli_find_files(const char *path, void (*cb)(char *, struct dirent *)) { DIR *d; + struct stat st; struct dirent *dp; char *fpath; @@ -739,12 +740,20 @@ cli_find_files(const char *path, void (*cb)(char *, struct dirent *)) continue; (void)cli_vasprintf(&fpath, "%s/%s", path, dp->d_name); + if (stat(fpath, &st) == -1) { + fprintf(stderr, "stat(%s): %s\n", fpath, errno_s); + free(fpath); + continue; + } - if (dp->d_type == DT_DIR) { + if (S_ISDIR(st.st_mode)) { cli_find_files(fpath, cb); free(fpath); - } else { + } else if (S_ISREG(st.st_mode)) { cb(fpath, dp); + } else { + fprintf(stderr, "ignoring %s\n", fpath); + free(fpath); } }