소스 검색

2009-03-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Rewritten isSameFileBeingDownloaded()
	* src/RequestGroupMan.cc
Tatsuhiro Tsujikawa 16 년 전
부모
커밋
173a86febc
2개의 변경된 파일34개의 추가작업 그리고 5개의 파일을 삭제
  1. 5 0
      ChangeLog
  2. 29 5
      src/RequestGroupMan.cc

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2009-03-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Rewritten isSameFileBeingDownloaded()
+	* src/RequestGroupMan.cc
+
 2009-03-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Removed getName() from DownloadContext. getName() is declared in

+ 29 - 5
src/RequestGroupMan.cc

@@ -63,6 +63,7 @@
 #include "File.h"
 #include "Util.h"
 #include "Command.h"
+#include "FileEntry.h"
 
 namespace aria2 {
 
@@ -508,20 +509,43 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con
   return o.str();
 }
 
+template<typename StringInputIterator, typename FileEntryInputIterator>
+static bool sameFilePathExists(StringInputIterator sfirst,
+			       StringInputIterator slast,
+			       FileEntryInputIterator ffirst,
+			       FileEntryInputIterator flast)
+{
+  for(; ffirst != flast; ++ffirst) {
+    if(std::binary_search(sfirst, slast, (*ffirst)->getPath())) {
+      return true;
+    }
+  }
+  return false;
+}
+
 bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) const
 {
-  // TODO it may be good to use dedicated method rather than use isPreLocalFileCheckEnabled
+  // TODO it may be good to use dedicated method rather than use
+  // isPreLocalFileCheckEnabled
   if(!requestGroup->isPreLocalFileCheckEnabled()) {
     return false;
   }
+  std::deque<std::string> files;
   for(RequestGroups::const_iterator itr = _requestGroups.begin();
       itr != _requestGroups.end(); ++itr) {
-    if((*itr).get() != requestGroup &&
-       (*itr)->getFilePath() == requestGroup->getFilePath()) {
-      return true;
+    if((*itr).get() != requestGroup) {
+      std::deque<SharedHandle<FileEntry> > entries =
+	(*itr)->getDownloadContext()->getFileEntries();
+      std::transform(entries.begin(), entries.end(),
+		     std::back_inserter(files),
+		     mem_fun_sh(&FileEntry::getPath));
     }
   }
-  return false;
+  std::sort(files.begin(), files.end());
+  std::deque<SharedHandle<FileEntry> > entries =
+    requestGroup->getDownloadContext()->getFileEntries();
+  return sameFilePathExists(files.begin(), files.end(),
+			    entries.begin(), entries.end());
 }
 
 void RequestGroupMan::halt()