diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-02-07 09:13:08 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-02-07 09:13:08 -0800 |
commit | d24b192f8c724662e1a8f93fd8e72d79dba04a86 (patch) | |
tree | 280842817b6d3095ba56ef49414343e998671d03 | |
parent | 0442d7e2d66e54bfe2462aabf2362f3fecdd7b4c (diff) | |
download | infinitytier-d24b192f8c724662e1a8f93fd8e72d79dba04a86.tar.gz infinitytier-d24b192f8c724662e1a8f93fd8e72d79dba04a86.zip |
Remove old updates from updates.d on Node startup.
-rw-r--r-- | node/Node.cpp | 1 | ||||
-rw-r--r-- | node/SoftwareUpdater.cpp | 11 | ||||
-rw-r--r-- | node/SoftwareUpdater.hpp | 5 |
3 files changed, 17 insertions, 0 deletions
diff --git a/node/Node.cpp b/node/Node.cpp index fe3407be..23ec01de 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -461,6 +461,7 @@ Node::ReasonForTermination Node::run() #ifdef ZT_AUTO_UPDATE if (ZT_DEFAULTS.updateLatestNfoURL.length()) { _r->updater = new SoftwareUpdater(_r); + _r->updater->cleanOldUpdates(); // clean out updates.d on startup } else { LOG("WARNING: unable to enable software updates: latest .nfo URL from ZT_DEFAULTS is empty (does this platform actually support software updates?)"); } diff --git a/node/SoftwareUpdater.cpp b/node/SoftwareUpdater.cpp index 0ce946ad..4d11afa9 100644 --- a/node/SoftwareUpdater.cpp +++ b/node/SoftwareUpdater.cpp @@ -41,6 +41,7 @@ #include "RuntimeEnvironment.hpp" #include "Thread.hpp" #include "Node.hpp" +#include "Utils.hpp" #ifdef __UNIX_LIKE__ #include <unistd.h> @@ -74,6 +75,16 @@ SoftwareUpdater::~SoftwareUpdater() } } +void SoftwareUpdater::cleanOldUpdates() +{ + std::string updatesDir(_r->homePath + ZT_PATH_SEPARATOR_S + "updates.d"); + std::map<std::string,bool> dl(Utils::listDirectory(updatesDir.c_str())); + for(std::map<std::string,bool>::iterator i(dl.begin());i!=dl.end();++i) { + if (!i->second) + Utils::rm(i->first.c_str()); + } +} + const char *SoftwareUpdater::parseNfo( const char *nfoText, unsigned int &vMajor, diff --git a/node/SoftwareUpdater.hpp b/node/SoftwareUpdater.hpp index ead3eb1f..aed5382c 100644 --- a/node/SoftwareUpdater.hpp +++ b/node/SoftwareUpdater.hpp @@ -53,6 +53,11 @@ public: ~SoftwareUpdater(); /** + * Remove old updates in updates.d + */ + void cleanOldUpdates(); + + /** * Called on each version message from a peer * * If a peer has a newer version, that causes an update to be started. |