← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2422: Don't duplicate file list entries when re-downloading it

 

------------------------------------------------------------
revno: 2422
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2011-02-12 18:03:41 +0100
message:
  Don't duplicate file list entries when re-downloading it
modified:
  changelog.txt
  dcpp/DirectoryListing.cpp
  dcpp/DirectoryListing.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	2011-02-11 23:08:25 +0000
+++ changelog.txt	2011-02-12 17:03:41 +0000
@@ -9,6 +9,7 @@
 * More status bar icons
 * [L#704743] Fix hang on exit under WINE in active mode (cologic)
 * Add NAT-PMP for port mappings as an alternative to UPnP (poy)
+* [L#654483] Don't duplicate file list entries when re-downloading it (poy)
 
 -- 0.781 2011-01-12 --
 * Add a dummy serial number to TLS certs to satisfy some parsers (poy)

=== modified file 'dcpp/DirectoryListing.cpp'
--- dcpp/DirectoryListing.cpp	2011-01-02 17:12:02 +0000
+++ dcpp/DirectoryListing.cpp	2011-02-12 17:03:41 +0000
@@ -148,15 +148,34 @@
 			const string& n = getAttrib(attribs, sName, 0);
 			if(n.empty())
 				return;
+
 			const string& s = getAttrib(attribs, sSize, 1);
 			if(s.empty())
 				return;
+			auto size = Util::toInt64(s);
+
 			const string& h = getAttrib(attribs, sTTH, 2);
-			if(h.empty()) {
+			if(h.empty())
 				return;
+			TTHValue tth(h); /// @todo verify validity?
+
+			if(updating) {
+				// just update the current file if it is already there.
+				for(auto i = cur->files.cbegin(), iend = cur->files.cend(); i != iend; ++i) {
+					auto& file = **i;
+					/// @todo comparisons should be case-insensitive but it takes too long - add a cache
+					if(file.getTTH() == tth || file.getName() == n) {
+						file.setName(n);
+						file.setSize(size);
+						file.setTTH(tth);
+						return;
+					}
+				}
 			}
-			DirectoryListing::File* f = new DirectoryListing::File(cur, n, Util::toInt64(s), h);
+
+			DirectoryListing::File* f = new DirectoryListing::File(cur, n, size, tth);
 			cur->files.push_back(f);
+
 		} else if(name == sDirectory) {
 			const string& n = getAttrib(attribs, sName, 0);
 			if(n.empty()) {
@@ -166,6 +185,7 @@
 			DirectoryListing::Directory* d = NULL;
 			if(updating) {
 				for(DirectoryListing::Directory::Iter i = cur->directories.begin(); i != cur->directories.end(); ++i) {
+					/// @todo comparisons should be case-insensitive but it takes too long - add a cache
 					if((*i)->getName() == n) {
 						d = *i;
 						if(!d->getComplete())

=== modified file 'dcpp/DirectoryListing.h'
--- dcpp/DirectoryListing.h	2011-01-02 17:12:02 +0000
+++ dcpp/DirectoryListing.h	2011-02-12 17:03:41 +0000
@@ -45,7 +45,7 @@
 		typedef vector<Ptr> List;
 		typedef List::iterator Iter;
 
-		File(Directory* aDir, const string& aName, int64_t aSize, const string& aTTH) throw() :
+		File(Directory* aDir, const string& aName, int64_t aSize, const TTHValue& aTTH) throw() :
 			name(aName), size(aSize), parent(aDir), tthRoot(aTTH), adls(false)
 		{
 		}