← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3189: Fix invalid share sizes after a directory merge; remove obsolete cached share loader

 

------------------------------------------------------------
revno: 3189
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2013-01-25 21:29:34 +0100
message:
  Fix invalid share sizes after a directory merge; remove obsolete cached share loader
modified:
  changelog.txt
  dcpp/ShareManager.cpp
  dcpp/ShareManager.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2013-01-24 22:53:46 +0000
+++ changelog.txt	2013-01-25 20:29:34 +0000
@@ -22,6 +22,7 @@
 * [ADC] Revise INF order in c-c connections as advised by ADC 1.0.2
 * Add hublist.eu to default hub lists
 * Add a toolbar button to open own file list (poy)
+* [L#489704] Fix invalid share sizes after a directory merge (poy)
 
 Note: The hash registry will be upgraded when running this version for the
 first time. Make sure all your drives are connected to avoid re-hashing.

=== modified file 'dcpp/ShareManager.cpp'
--- dcpp/ShareManager.cpp	2013-01-18 21:28:38 +0000
+++ dcpp/ShareManager.cpp	2013-01-25 20:29:34 +0000
@@ -54,7 +54,7 @@
 atomic_flag ShareManager::refreshing = ATOMIC_FLAG_INIT;
 
 ShareManager::ShareManager() : hits(0), xmlListLen(0), bzXmlListLen(0),
-	xmlDirty(true), forceXmlRefresh(true), refreshDirs(false), update(false), initial(true), listN(0),
+	xmlDirty(true), forceXmlRefresh(true), refreshDirs(false), update(false), listN(0),
 	lastXmlUpdate(0), lastFullUpdate(GET_TICK()), bloom(1<<20)
 {
 	SettingsManager::getInstance()->addListener(this);
@@ -370,84 +370,6 @@
 	}
 }
 
-static const string SDIRECTORY = "Directory";
-static const string SFILE = "File";
-static const string SNAME = "Name";
-static const string SSIZE = "Size";
-static const string STTH = "TTH";
-
-struct ShareLoader : public SimpleXMLReader::CallBack {
-	ShareLoader(decltype(ShareManager::directories)& aDirs) : dirs(aDirs), cur(0), depth(0) { }
-	void startTag(const string& name, StringPairList& attribs, bool simple) {
-		if(name == SDIRECTORY) {
-			const string& name = getAttrib(attribs, SNAME, 0);
-			if(!name.empty()) {
-				if(depth == 0) {
-					auto i = dirs.find(name);
-					if(i != dirs.end()) {
-						cur = i->second;
-					}
-				} else if(cur) {
-					cur = ShareManager::Directory::create(name, cur);
-					cur->getParent()->directories[cur->getName()] = cur;
-				}
-			}
-
-			if(simple) {
-				if(cur) {
-					cur = cur->getParent();
-				}
-			} else {
-				depth++;
-			}
-		} else if(cur && name == SFILE) {
-			const string& fname = getAttrib(attribs, SNAME, 0);
-			const string& size = getAttrib(attribs, SSIZE, 1);
-			const string& root = getAttrib(attribs, STTH, 2);
-			if(fname.empty() || size.empty() || (root.size() != 39)) {
-				dcdebug("Invalid file found: %s\n", fname.c_str());
-				return;
-			}
-			cur->files.insert(ShareManager::Directory::File(fname, Util::toInt64(size), cur, TTHValue(root)));
-		}
-	}
-	void endTag(const string& name) {
-		if(name == SDIRECTORY) {
-			depth--;
-			if(cur) {
-				cur = cur->getParent();
-			}
-		}
-	}
-
-private:
-	decltype(ShareManager::directories)& dirs;
-
-	ShareManager::Directory::Ptr cur;
-	size_t depth;
-};
-
-bool ShareManager::loadCache() noexcept {
-	try {
-		ShareLoader loader(directories);
-		SimpleXMLReader xml(&loader);
-
-		dcpp::File ff(Util::getPath(Util::PATH_USER_CONFIG) + "files.xml.bz2", dcpp::File::READ, dcpp::File::OPEN);
-		FilteredInputStream<UnBZFilter, false> f(&ff);
-
-		xml.parse(f);
-
-		for(const auto& i: directories) {
-			updateIndices(*i.second);
-		}
-
-		return true;
-	} catch(const Exception& e) {
-		dcdebug("%s\n", e.getError().c_str());
-	}
-	return false;
-}
-
 void ShareManager::save(SimpleXML& aXml) {
 	Lock l(cs);
 
@@ -494,28 +416,26 @@
 	string vName = validateVirtual(virtualName);
 	dp->setName(vName);
 
-	{
-		Lock l(cs);
-
-		shares[realPath] = move(vName);
-		updateIndices(*merge(dp, realPath));
-
-		setDirty();
-	}
+	Lock l(cs);
+
+	shares[realPath] = move(vName);
+
+	merge(dp, realPath);
+
+	rebuildIndices();
+	setDirty();
 }
 
-ShareManager::Directory::Ptr ShareManager::merge(const Directory::Ptr& directory, const string& realPath) {
+void ShareManager::merge(const Directory::Ptr& directory, const string& realPath) {
 	auto i = directories.find(directory->getName());
 	if(i != directories.end()) {
 		dcdebug("Merging directory <%s> into %s\n", realPath.c_str(), directory->getName().c_str());
 		i->second->merge(directory, realPath);
-		return i->second;
+
+	} else {
+		dcdebug("Adding new directory %s\n", directory->getName().c_str());
+		directories[directory->getName()] = directory;
 	}
-
-	dcdebug("Adding new directory %s\n", directory->getName().c_str());
-
-	directories[directory->getName()] = directory;
-	return directory;
 }
 
 void ShareManager::Directory::merge(const Directory::Ptr& source, const string& realPath) {
@@ -782,14 +702,9 @@
 	update = aUpdate;
 	refreshDirs = dirs;
 	join();
-	bool cached = false;
-	if(initial) {
-		cached = loadCache();
-		initial = false;
-	}
 	try {
 		start();
-		if(block && !cached) {
+		if(block) {
 			join();
 		} else {
 			setThreadPriority(Thread::LOW);

=== modified file 'dcpp/ShareManager.h'
--- dcpp/ShareManager.h	2013-01-18 21:28:38 +0000
+++ dcpp/ShareManager.h	2013-01-25 20:29:34 +0000
@@ -253,7 +253,6 @@
 	bool forceXmlRefresh; /// bypass the 15-minutes guard
 	bool refreshDirs;
 	bool update;
-	bool initial;
 
 	int listN;
 
@@ -285,10 +284,9 @@
 	void updateIndices(Directory& aDirectory);
 	void updateIndices(Directory& dir, const decltype(std::declval<Directory>().files.begin())& i);
 
-	Directory::Ptr merge(const Directory::Ptr& directory, const string& realPath);
+	void merge(const Directory::Ptr& directory, const string& realPath);
 
 	void generateXmlList();
-	bool loadCache() noexcept;
 	pair<Directory::Ptr, string> splitVirtual(const string& virtualPath) const;
 	string findRealRoot(const string& virtualRoot, const string& virtualLeaf) const;