[sword-svn] r3417 - trunk/src/mgr

scribe at crosswire.org scribe at crosswire.org
Sat Apr 23 11:01:15 MST 2016


Author: scribe
Date: 2016-04-23 11:01:15 -0700 (Sat, 23 Apr 2016)
New Revision: 3417

Modified:
   trunk/src/mgr/remotetrans.cpp
Log:
Fix for bug API-184; patch from Kostya Maslyuk
Recurse folders first to build file list to more accurate total bytes
can be reported to user

Modified: trunk/src/mgr/remotetrans.cpp
===================================================================
--- trunk/src/mgr/remotetrans.cpp	2016-03-15 14:07:18 UTC (rev 3416)
+++ trunk/src/mgr/remotetrans.cpp	2016-04-23 18:01:15 UTC (rev 3417)
@@ -1,4 +1,4 @@
-/*****************************************************************************
+/*****************************************************************************
  *
  *  remotetrans.cpp -	
  *
@@ -125,10 +125,9 @@
 
 
 int RemoteTransport::copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
-SWLog::getSystemLog()->logDebug("RemoteTransport::copyDirectory");
-	unsigned int i;
+	SWLog::getSystemLog()->logDebug("RemoteTransport::copyDirectory");
 	int retVal = 0;
-	
+
 	SWBuf url = SWBuf(urlPrefix) + SWBuf(dir);
 	removeTrailingSlash(url);
 	url += '/';
@@ -140,10 +139,31 @@
 		SWLog::getSystemLog()->logWarning("NetTransport: failed to read dir %s\n", url.c_str());
 		return -1;
 	}
-				
+
+	// append files in sub directories and calculate total download size
+	unsigned int i = 0;
 	long totalBytes = 0;
-	for (i = 0; i < dirList.size(); i++)
-		totalBytes += dirList[i].size;
+	for (;;) {
+		if (i == dirList.size())
+			break;
+
+		struct DirEntry &e = dirList.at(i);
+
+		if (e.isDirectory) {
+			SWBuf name(e.name); // &e will be invalidated after first insertion
+			vector<struct DirEntry> sd = getDirList((url + name + '/').c_str());
+			for (unsigned int ii = 0; ii < sd.size(); ii++) {
+				sd[ii].name = name + '/' + sd[ii].name;
+				dirList.push_back(sd[ii]);
+			}
+			dirList.erase(dirList.begin() + i);
+		}
+		else {
+			totalBytes += e.size;
+			i++;
+		}
+	}
+
 	long completedBytes = 0;
 	for (i = 0; i < dirList.size(); i++) {
 		struct DirEntry &dirEntry = dirList[i];
@@ -165,23 +185,12 @@
 				SWBuf url = (SWBuf)urlPrefix + (SWBuf)dir;
 				removeTrailingSlash(url);
 				url += "/";
-				url += dirEntry.name; //dont forget the final slash
-				if (!dirEntry.isDirectory) {
-					if (getURL(buffer.c_str(), url.c_str())) {
-						SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", url.c_str());
-						return -2;
-					}
-					completedBytes += dirEntry.size;
+				url += dirEntry.name;
+				if (getURL(buffer.c_str(), url.c_str())) {
+					SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", url.c_str());
+					return -2;
 				}
-				else {
-					SWBuf subdir = (SWBuf)dir;
-					removeTrailingSlash(subdir);
-					subdir += (SWBuf)"/" + dirEntry.name;
-					if (copyDirectory(urlPrefix, subdir, buffer.c_str(), suffix)) {
-						SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", subdir.c_str());
-						return -2;
-					}
-				}
+				completedBytes += dirEntry.size;
 			}
 			SWCATCH (...) {}
 			if (term) {




More information about the sword-cvs mailing list