Just return files from listDirectory() since that is all we need, fix network request on network restore logic, and remember saved networks in service/One

This commit is contained in:
Adam Ierymenko 2015-04-14 15:32:05 -07:00
parent 29a2175b7a
commit 347e98dcd2
4 changed files with 20 additions and 16 deletions

View File

@ -67,6 +67,7 @@ Network::Network(const RuntimeEnvironment *renv,uint64_t nwid) :
std::string conf(RR->node->dataStoreGet(confn));
if (conf.length()) {
setConfiguration(Dictionary(conf),false);
_lastConfigUpdate = 0; // we still want to re-request a new config from the network
gotConf = true;
}
} catch ( ... ) {} // ignore invalids, we'll re-request

View File

@ -75,38 +75,35 @@ bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
}
#endif // __UNIX_LIKE__
std::map<std::string,bool> OSUtils::listDirectory(const char *path)
std::vector<std::string> OSUtils::listDirectory(const char *path)
{
std::map<std::string,bool> r;
std::vector<std::string> r;
#ifdef __WINDOWS__
HANDLE hFind;
WIN32_FIND_DATAA ffd;
if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) {
do {
if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,"..")))
r[std::string(ffd.cFileName)] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0))
r.push_back(std::string(ffd.cFileName));
} while (FindNextFileA(hFind,&ffd));
FindClose(hFind);
}
#else
struct dirent de;
struct dirent *dptr;
DIR *d = opendir(path);
if (!d)
return r;
dptr = (struct dirent *)0;
for(;;) {
if (readdir_r(d,&de,&dptr))
break;
if (dptr) {
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,"..")))
r[std::string(dptr->d_name)] = (dptr->d_type == DT_DIR);
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type != DT_DIR))
r.push_back(std::string(dptr->d_name));
} else break;
}
closedir(d);
#endif

View File

@ -103,16 +103,13 @@ public:
/**
* List a directory's contents
*
* Keys in returned map are filenames only and don't include the leading
* path. Pseudo-paths like . and .. are not returned. Values are true if
* the item is a directory, false if it's a file. More detailed attributes
* aren't supported since the code that uses this doesn't need them.
*
* This returns only files, not sub-directories.
*
* @param path Path to list
* @return Map of entries and whether or not they are also directories (empty on failure)
* @return Names of files in directory
*/
static std::map<std::string,bool> listDirectory(const char *path);
static std::vector<std::string> listDirectory(const char *path);
/**
* Set modes on a file to something secure

View File

@ -191,6 +191,15 @@ public:
_controlPlane = new ControlPlane(_node);
{
std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str()));
for(std::vector<std::string>::iterator f(networksDotD.begin());f!=networksDotD.end();++f) {
std::size_t dot = f->find_last_of('.');
if ((dot == 16)&&(f->substr(16) == ".conf"))
_node->join(Utils::hexStrToU64(f->substr(0,dot).c_str()));
}
}
_nextBackgroundTaskDeadline = 0;
for(;;) {
_run_m.lock();