소스 검색

2009-11-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Use createRequestGroupForUri to create the download for torrent
	file.
	* src/Metalink2RequestGroup.cc
	* test/Metalink2RequestGroupTest.cc
Tatsuhiro Tsujikawa 16 년 전
부모
커밋
96205abc67
3개의 변경된 파일28개의 추가작업 그리고 20개의 파일을 삭제
  1. 7 0
      ChangeLog
  2. 21 18
      src/Metalink2RequestGroup.cc
  3. 0 2
      test/Metalink2RequestGroupTest.cc

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2009-11-28  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Use createRequestGroupForUri to create the download for torrent
+	file.
+	* src/Metalink2RequestGroup.cc
+	* test/Metalink2RequestGroupTest.cc
+
 2009-11-28  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed typo

+ 21 - 18
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<std::string> uris;
       uris.push_back((*itr)->url);
-      torrentRg.reset(new RequestGroup(option));
-      SharedHandle<DownloadContext> 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<PreDownloadHandler> preh(new MemoryBufferPreDownloadHandler());
       {
+	std::deque<SharedHandle<RequestGroup> > 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<PreDownloadHandler> preh
+	  (new MemoryBufferPreDownloadHandler());
 	SharedHandle<RequestGroupCriteria> 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();

+ 0 - 2
test/Metalink2RequestGroupTest.cc

@@ -97,8 +97,6 @@ void Metalink2RequestGroupTest::testGenerate()
     const SharedHandle<DownloadContext>& 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