diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index b7b740a0b..0884dedae 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1129,7 +1129,8 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE( } else { Mutex::Lock _l(_db_m); - std::string pfx("network/"); pfx.append(nwids); + std::string pfx("network/"); + pfx.append(nwids); _db.filter(pfx,[](const std::string &n,const json &obj) { return false; // delete }); diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp index 8b6de9b4a..756664eb4 100644 --- a/controller/JSONDB.cpp +++ b/controller/JSONDB.cpp @@ -99,8 +99,9 @@ void JSONDB::erase(const std::string &n) void JSONDB::_reload(const std::string &p,const std::string &b) { - std::vector dl(OSUtils::listDirectory(p.c_str())); + std::vector dl(OSUtils::listDirectory(p.c_str(),true)); for(std::vector::const_iterator di(dl.begin());di!=dl.end();++di) { + printf("%s\n",di->c_str()); if ((di->length() > 5)&&(di->substr(di->length() - 5) == ".json")) { this->get(b + di->substr(0,di->length() - 5)); } else { diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 33e143dad..fd5efed09 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -73,7 +73,7 @@ bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath) } #endif // __UNIX_LIKE__ -std::vector OSUtils::listDirectory(const char *path) +std::vector OSUtils::listDirectory(const char *path,bool includeDirectories) { std::vector r; @@ -82,7 +82,7 @@ std::vector OSUtils::listDirectory(const char *path) WIN32_FIND_DATAA ffd; if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) { do { - if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)) + if ( (strcmp(ffd.cFileName,".")) && (strcmp(ffd.cFileName,"..")) && (((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)||(((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)&&(includeDirectories))) ) r.push_back(std::string(ffd.cFileName)); } while (FindNextFileA(hFind,&ffd)); FindClose(hFind); @@ -98,7 +98,7 @@ std::vector OSUtils::listDirectory(const char *path) if (readdir_r(d,&de,&dptr)) break; if (dptr) { - if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type != DT_DIR)) + if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&((dptr->d_type != DT_DIR)||(includeDirectories))) r.push_back(std::string(dptr->d_name)); } else break; } diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp index 2e007ef24..b84d5d2d7 100644 --- a/osdep/OSUtils.hpp +++ b/osdep/OSUtils.hpp @@ -104,12 +104,11 @@ public: /** * List a directory's contents * - * This returns only files, not sub-directories. - * * @param path Path to list + * @param includeDirectories If true, include directories as well as files * @return Names of files in directory (without path prepended) */ - static std::vector listDirectory(const char *path); + static std::vector listDirectory(const char *path,bool includeDirectories = false); /** * Clean a directory of files whose last modified time is older than this