aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-10-24 22:19:06 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:12:02 +0100
commitebaea15fbbd3009f0fc4b778391f1fbf44202bea (patch)
tree769ffbb3d089f1b749f71afb320cf2c9e5a9db91
parentcabfef0ff81395a2286e11b416ae07f22e335730 (diff)
Fix to support pre-V3 DynAPI
-rw-r--r--filescan-utils.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/filescan-utils.c b/filescan-utils.c
index 7e45133..37cc2b3 100644
--- a/filescan-utils.c
+++ b/filescan-utils.c
@@ -32,14 +32,16 @@ PUBLIC json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode,
char *dirPath;
char* dirList= strdup(searchPath);
size_t extLen=0;
+ int count=0;
- void ScanDir (char *searchPath) {
- DIR *dirHandle;
+ int ScanDir (char *searchPath) {
+ int found=0;
+ DIR *dirHandle;
struct dirent *dirEnt;
dirHandle = opendir (searchPath);
if (!dirHandle) {
AFB_DEBUG ("CONFIG-SCANNING dir=%s not readable", searchPath);
- return;
+ return 0;
}
//AFB_NOTICE ("CONFIG-SCANNING:ctl_listconfig scanning: %s", searchPath);
@@ -53,7 +55,7 @@ PUBLIC json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode,
strncpy(newpath, searchPath, sizeof(newpath));
strncat(newpath, "/", sizeof(newpath)-strlen(newpath)-1);
strncat(newpath, dirEnt->d_name, sizeof(newpath)-strlen(newpath)-1);
- ScanDir(newpath);
+ found += ScanDir(newpath);
continue;
}
@@ -70,9 +72,11 @@ PUBLIC json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode,
json_object_object_add(pathJ, "fullpath", json_object_new_string(searchPath));
json_object_object_add(pathJ, "filename", json_object_new_string(dirEnt->d_name));
json_object_array_add(responseJ, pathJ);
+ found ++;
}
}
closedir(dirHandle);
+ return found;
}
if (ext) extLen=strlen(ext);
@@ -80,9 +84,13 @@ PUBLIC json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode,
// loop recursively on dir
for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
- ScanDir (dirPath);
+ count += ScanDir (dirPath);
}
-
+ if (count == 0) {
+ json_object_put (responseJ);
+ return NULL;
+ }
+
return (responseJ);
}