summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-10-24 22:19:06 +0200
committerFulup Ar Foll <fulup@iot.bzh>2017-10-24 22:19:06 +0200
commit77c12fc3a44ce4fd1f4a83019547190d0f44549a (patch)
tree769ffbb3d089f1b749f71afb320cf2c9e5a9db91
parentfd86e75feab42c0d0676a80e9aa415fa507e9a5f (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);
}