diff --git a/ChangeLog b/ChangeLog index 3e4f06c4..6d672ed6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-10 Tatsuhiro Tsujikawa + + Rewritten isSameFileBeingDownloaded() + * src/RequestGroupMan.cc + 2009-03-10 Tatsuhiro Tsujikawa Removed getName() from DownloadContext. getName() is declared in diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 8ea90783..fd03274c 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -63,6 +63,7 @@ #include "File.h" #include "Util.h" #include "Command.h" +#include "FileEntry.h" namespace aria2 { @@ -508,22 +509,45 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con return o.str(); } -bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) const +template +static bool sameFilePathExists(StringInputIterator sfirst, + StringInputIterator slast, + FileEntryInputIterator ffirst, + FileEntryInputIterator flast) { - // TODO it may be good to use dedicated method rather than use isPreLocalFileCheckEnabled - if(!requestGroup->isPreLocalFileCheckEnabled()) { - return false; - } - for(RequestGroups::const_iterator itr = _requestGroups.begin(); - itr != _requestGroups.end(); ++itr) { - if((*itr).get() != requestGroup && - (*itr)->getFilePath() == requestGroup->getFilePath()) { + 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 + if(!requestGroup->isPreLocalFileCheckEnabled()) { + return false; + } + std::deque files; + for(RequestGroups::const_iterator itr = _requestGroups.begin(); + itr != _requestGroups.end(); ++itr) { + if((*itr).get() != requestGroup) { + std::deque > entries = + (*itr)->getDownloadContext()->getFileEntries(); + std::transform(entries.begin(), entries.end(), + std::back_inserter(files), + mem_fun_sh(&FileEntry::getPath)); + } + } + std::sort(files.begin(), files.end()); + std::deque > entries = + requestGroup->getDownloadContext()->getFileEntries(); + return sameFilePathExists(files.begin(), files.end(), + entries.begin(), entries.end()); +} + void RequestGroupMan::halt() { for(RequestGroups::const_iterator itr = _requestGroups.begin();