summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-11-04 15:18:31 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-11-04 15:18:31 -0700
commitb03c7b2f30b18cc2d243bd226612d911f158bdc4 (patch)
treee8a821077cf7e2ce871704dfc903e6048e3fb2bd /osdep
parentab2ccb094aa2b122876668cccb13f755d56c208b (diff)
downloadinfinitytier-b03c7b2f30b18cc2d243bd226612d911f158bdc4.tar.gz
infinitytier-b03c7b2f30b18cc2d243bd226612d911f158bdc4.zip
Refactor controller to use split-out DB for better performance and less ugly.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/OSUtils.cpp16
-rw-r--r--osdep/OSUtils.hpp6
2 files changed, 12 insertions, 10 deletions
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp
index c652e272..4a81625b 100644
--- a/osdep/OSUtils.cpp
+++ b/osdep/OSUtils.cpp
@@ -107,17 +107,18 @@ std::vector<std::string> OSUtils::listDirectory(const char *path)
return r;
}
-std::vector<std::string> OSUtils::listSubdirectories(const char *path)
+std::map<std::string,char> OSUtils::listDirectoryFull(const char *path)
{
- std::vector<std::string> r;
+ std::map<std::string,char> 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,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0))
- r.push_back(std::string(ffd.cFileName));
+ if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))) {
+ r[ffd.cFileName] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) ? 'd' : 'f';
+ }
} while (FindNextFileA(hFind,&ffd));
FindClose(hFind);
}
@@ -132,8 +133,9 @@ std::vector<std::string> OSUtils::listSubdirectories(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))
- r.push_back(std::string(dptr->d_name));
+ if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))) {
+ r[dptr->d_name] = (dptr->d_type == DT_DIR) ? 'd' : 'f';
+ }
} else break;
}
closedir(d);
@@ -178,7 +180,7 @@ bool OSUtils::rmDashRf(const char *path)
std::string p(path);
p.push_back(ZT_PATH_SEPARATOR);
p.append(dptr->d_name);
- if (unlink(p.c_str()) != 0) {
+ if (unlink(p.c_str()) != 0) { // unlink first will remove symlinks instead of recursing them
if (!rmDashRf(p.c_str()))
return false;
}
diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp
index 4f74344f..c481780b 100644
--- a/osdep/OSUtils.hpp
+++ b/osdep/OSUtils.hpp
@@ -110,12 +110,12 @@ public:
static std::vector<std::string> listDirectory(const char *path);
/**
- * List a directory's subdirectories
+ * List all contents in a directory
*
* @param path Path to list
- * @return Names of subdirectories (without path prepended)
+ * @return Names of things and types, currently just 'f' and 'd'
*/
- static std::vector<std::string> listSubdirectories(const char *path);
+ static std::map<std::string,char> listDirectoryFull(const char *path);
/**
* Delete a directory and all its files and subdirectories recursively