summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2017-03-08 10:38:43 -0800
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2017-03-08 10:38:43 -0800
commit4b511d80a1edc1eabd6f47a22810030b54474603 (patch)
treeb5adf12565c76e3d2f5ab6dc91db82d0cb39f04c /osdep
parenta74e9e1dd3302891cc3c65d918994086d868dc19 (diff)
downloadinfinitytier-4b511d80a1edc1eabd6f47a22810030b54474603.tar.gz
infinitytier-4b511d80a1edc1eabd6f47a22810030b54474603.zip
Windows directory cleanup and a Windows build fix.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/OSUtils.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp
index 8427f0a0..6b95258c 100644
--- a/osdep/OSUtils.cpp
+++ b/osdep/OSUtils.cpp
@@ -152,9 +152,22 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
#ifdef __WINDOWS__
HANDLE hFind;
WIN32_FIND_DATAA ffd;
+ LARGE_INTEGER date,adjust;
+ adjust.QuadPart = 11644473600000 * 10000;
+ char tmp[4096];
if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) {
do {
- if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))) {
+ if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))&&((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)) {
+ date.HighPart = ffd.ftLastWriteTime.dwHighDateTime;
+ date.LowPart = ffd.ftLastWriteTime.dwLowDateTime;
+ if (date.QuadPart > 0) {
+ date.QuadPart -= adjust.QuadPart;
+ if (((date.QuadPart / 10000000) * 1000) < olderThan) {
+ Utils::snprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
+ if (DeleteFileA(tmp))
+ ++cleaned;
+ }
+ }
}
} while (FindNextFileA(hFind,&ffd));
FindClose(hFind);
@@ -414,7 +427,7 @@ std::string OSUtils::platformDefaultHomePath()
}
// Inline these massive JSON operations in one place only to reduce binary footprint and compile time
-nlohmann::json OSUtils::jsonParse(const std::string &buf) { return nlohmann::json::parse(buf); }
+nlohmann::json OSUtils::jsonParse(const std::string &buf) { return nlohmann::json::parse(buf.c_str()); }
std::string OSUtils::jsonDump(const nlohmann::json &j) { return j.dump(1); }
uint64_t OSUtils::jsonInt(const nlohmann::json &jv,const uint64_t dfl)