Browse Source

Remove old updates from updates.d on Node startup.

Adam Ierymenko 11 years ago
parent
commit
d24b192f8c
3 changed files with 17 additions and 0 deletions
  1. 1 0
      node/Node.cpp
  2. 11 0
      node/SoftwareUpdater.cpp
  3. 5 0
      node/SoftwareUpdater.hpp

+ 1 - 0
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?)");
 		}

+ 11 - 0
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,

+ 5 - 0
node/SoftwareUpdater.hpp

@@ -52,6 +52,11 @@ public:
 	SoftwareUpdater(const RuntimeEnvironment *renv);
 	~SoftwareUpdater();
 
+	/**
+	 * Remove old updates in updates.d
+	 */
+	void cleanOldUpdates();
+
 	/**
 	 * Called on each version message from a peer
 	 *