From 96205abc67e5f425e3bad997959493ba54d83190 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 Nov 2009 09:21:12 +0000 Subject: [PATCH] 2009-11-28 Tatsuhiro Tsujikawa Use createRequestGroupForUri to create the download for torrent file. * src/Metalink2RequestGroup.cc * test/Metalink2RequestGroupTest.cc --- ChangeLog | 7 ++++++ src/Metalink2RequestGroup.cc | 39 +++++++++++++++++-------------- test/Metalink2RequestGroupTest.cc | 2 -- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f1b1714..78994bc6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-11-28 Tatsuhiro Tsujikawa + + Use createRequestGroupForUri to create the download for torrent + file. + * src/Metalink2RequestGroup.cc + * test/Metalink2RequestGroupTest.cc + 2009-11-28 Tatsuhiro Tsujikawa Fixed typo diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 78718341..a43800d2 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -55,6 +55,7 @@ #include "a2functional.h" #ifdef ENABLE_BITTORRENT # include "BtDependency.h" +# include "download_helper.h" #endif // ENABLE_BITTORRENT #ifdef ENABLE_MESSAGE_DIGEST # include "Checksum.h" @@ -170,28 +171,30 @@ Metalink2RequestGroup::createRequestGroup if(itr != entry->resources.end()) { std::deque uris; uris.push_back((*itr)->url); - torrentRg.reset(new RequestGroup(option)); - SharedHandle dctx - (new DownloadContext(option->getAsInt(PREF_SEGMENT_SIZE), - 0, - A2STR::NIL)); - // Since torrent is downloaded in memory, setting dir has no effect. - //dctx->setDir(_option->get(PREF_DIR)); - dctx->getFirstFileEntry()->setUris(uris); - torrentRg->setDownloadContext(dctx); - torrentRg->clearPreDownloadHandler(); - torrentRg->clearPostDownloadHandler(); - // remove "metalink" from Accept Type list to avoid loop in tranparent - // metalink - torrentRg->removeAcceptType(RequestGroup::ACCEPT_METALINK); - // make it in-memory download - SharedHandle preh(new MemoryBufferPreDownloadHandler()); { + std::deque > result; + createRequestGroupForUri(result, option, uris, + /* ignoreForceSequential = */true, + /* ignoreLocalPath = */true); + if(!uris.empty()) { + torrentRg = result[0]; + } + } + if(!torrentRg.isNull()) { + torrentRg->setNumConcurrentCommand(1); + torrentRg->clearPreDownloadHandler(); + torrentRg->clearPostDownloadHandler(); + // remove "metalink" from Accept Type list to avoid loop in + // tranparent metalink + torrentRg->removeAcceptType(RequestGroup::ACCEPT_METALINK); + // make it in-memory download + SharedHandle preh + (new MemoryBufferPreDownloadHandler()); SharedHandle cri(new TrueRequestGroupCriteria()); preh->setCriteria(cri); + torrentRg->addPreDownloadHandler(preh); + groups.push_back(torrentRg); } - torrentRg->addPreDownloadHandler(preh); - groups.push_back(torrentRg); } #endif // ENABLE_BITTORRENT entry->reorderResourcesByPreference(); diff --git a/test/Metalink2RequestGroupTest.cc b/test/Metalink2RequestGroupTest.cc index 5df90552..570232cf 100644 --- a/test/Metalink2RequestGroupTest.cc +++ b/test/Metalink2RequestGroupTest.cc @@ -97,8 +97,6 @@ void Metalink2RequestGroupTest::testGenerate() const SharedHandle& dctx = rg->getDownloadContext(); CPPUNIT_ASSERT(!dctx.isNull()); - // PREF_DIR has no effect for internal torrent file download - CPPUNIT_ASSERT_EQUAL(std::string("."), dctx->getDir()); } #endif // ENABLE_BITTORRENT