summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2016-11-15 11:01:04 -0700
committerGeorge Joseph <gjoseph@digium.com>2016-11-15 21:21:59 -0500
commit3017f09f227258f21fbdcfeb05fb60064dd09b7d (patch)
tree9fc93dc577915ddfab647338197da36e8b1b33e0 /tests
parentd1739bcf07502e5e59917818dfcf514b95a6c2e3 (diff)
file.c/__ast_file_read_dirs: Fix issues on filesystems without d_type
One of the code paths in __ast_file_read_dirs will only get executed if the OS doesn't support dirent->d_type OR if the filesystem the particular file is on doesn't support it. So, while standard Linux systems support the field, some filesystems like XFS do not. In this case, we need to call stat() to determine whether the directory entry is a file or directory so we append the filename to the supplied directory path and call stat. We forgot to truncate path back to just the directory afterwards though so we were passing a complete file name to the callback in the dir_name parameter instead of just the directory name. The logic has been re-written to only create a full_path if we need to call stat() or if we need to descend into another directory. Change-Id: I54e4228bd8355fad65200c6df3ec4c9c8a98dfba
Diffstat (limited to 'tests')
-rw-r--r--tests/test_file.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/test_file.c b/tests/test_file.c
index 64bad9218..bb8a99584 100644
--- a/tests/test_file.c
+++ b/tests/test_file.c
@@ -21,7 +21,10 @@
<support_level>core</support_level>
***/
+
#include "asterisk.h"
+#include <sys/stat.h>
+#include <stdio.h>
#include "asterisk/file.h"
#include "asterisk/paths.h"
@@ -115,6 +118,17 @@ static char *test_files_get_one(struct _filenames *filenames, int num)
static int handle_find_file(const char *dir_name, const char *filename, void *obj)
{
+ struct stat statbuf;
+ char *full_path = ast_alloca(strlen(dir_name) + strlen(filename) + 2);
+
+ sprintf(full_path, "%s/%s", dir_name, filename);
+
+ errno = 0;
+ if (stat(full_path, &statbuf)) {
+ ast_log(LOG_ERROR, "Error reading path stats - %s: %s\n",
+ full_path, strerror(errno));
+ return 0;
+ }
/* obj contains the name of the file we are looking for */
return strcmp(obj, filename) ? 0 : FOUND;
}