瀏覽代碼

Add --pause-metadata option

This option pauses downloads created as a result of metadata
download. There are 3 types of metadata downloads in aria2: (1)
downloading .torrent file. (2) downloading torrent metadata using
magnet link. (3) downloading metalink file.  These metadata downloads
will generate downloads using their metadata. This option pauses these
subsequent downloads.
Tatsuhiro Tsujikawa 11 年之前
父節點
當前提交
e2932608fc

+ 1 - 0
doc/xmlrpc/aria2rpc

@@ -232,6 +232,7 @@ OptionParser.new do |opt|
   opt.on("--server-stat-of FILE"){|val| options["server-stat-of"]=val}
   opt.on("--save-cookies FILE"){|val| options["save-cookies"]=val}
   opt.on("--gid GID"){|val| options["gid"]=val}
+  opt.on("--pause-metadata [BOOL]",["true","false"]){|val| options["pause-metadata"]=val||"true"}
 
   opt.on("--server SERVER", "hostname of XML-RPC server. Default: localhost"){|val| options["server"]=val }
   opt.on("--port PORT", "port of XML-RPC server. Default: 6800"){|val| options["port"]=val }

+ 11 - 0
src/BtPostDownloadHandler.cc

@@ -52,6 +52,7 @@
 #include "DiskWriter.h"
 #include "AbstractSingleDiskAdaptor.h"
 #include "BencodeDiskWriter.h"
+#include "RequestGroupMan.h"
 
 namespace aria2 {
 
@@ -108,6 +109,16 @@ void BtPostDownloadHandler::getNextRequestGroups
   if(mi) {
     setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
   }
+
+  auto rgman = requestGroup->getRequestGroupMan();
+
+  if(rgman && rgman->getKeepRunning() &&
+     requestGroup->getOption()->getAsBool(PREF_PAUSE_METADATA)) {
+    for(auto& rg : newRgs) {
+      rg->setPauseRequested(true);
+    }
+  }
+
   groups.insert(groups.end(), newRgs.begin(), newRgs.end());
 }
 

+ 11 - 0
src/MetalinkPostDownloadHandler.cc

@@ -51,6 +51,7 @@
 #include "download_helper.h"
 #include "fmt.h"
 #include "FileEntry.h"
+#include "RequestGroupMan.h"
 
 namespace aria2 {
 
@@ -105,6 +106,16 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
     if(mi) {
       setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
     }
+
+    auto rgman = requestGroup->getRequestGroupMan();
+
+    if(rgman && rgman->getKeepRunning() &&
+       requestGroup->getOption()->getAsBool(PREF_PAUSE_METADATA)) {
+      for(auto& rg : newRgs) {
+        rg->setPauseRequested(true);
+      }
+    }
+
     groups.insert(groups.end(), newRgs.begin(), newRgs.end());
     diskAdaptor->closeFile();
   } catch(Exception& e) {

+ 13 - 0
src/OptionHandlerFactory.cc

@@ -679,6 +679,19 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
     op->setInitialOption(true);
     handlers.push_back(op);
   }
+  {
+    OptionHandler* op(new BooleanOptionHandler
+                      (PREF_PAUSE_METADATA,
+                       TEXT_PAUSE_METADATA,
+                       A2_V_FALSE,
+                       OptionHandler::OPT_ARG));
+    op->addTag(TAG_ADVANCED);
+    op->addTag(TAG_RPC);
+    op->setInitialOption(true);
+    op->setChangeGlobalOption(true);
+    op->setChangeOptionForReserved(true);
+    handlers.push_back(op);
+  }
   {
     OptionHandler* op(new BooleanOptionHandler
                       (PREF_QUIET,

+ 11 - 0
src/UTMetadataPostDownloadHandler.cc

@@ -50,6 +50,7 @@
 #include "prefs.h"
 #include "Option.h"
 #include "fmt.h"
+#include "RequestGroupMan.h"
 
 namespace aria2 {
 
@@ -107,6 +108,16 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
       setMetadataInfo(newRgs.begin(), newRgs.end(),
                       requestGroup->getMetadataInfo());
     }
+
+    auto rgman = requestGroup->getRequestGroupMan();
+
+    if(rgman && rgman->getKeepRunning() &&
+       requestGroup->getOption()->getAsBool(PREF_PAUSE_METADATA)) {
+      for(auto& rg : newRgs) {
+        rg->setPauseRequested(true);
+      }
+    }
+
     groups.insert(groups.end(), newRgs.begin(), newRgs.end());
   }
 }

+ 2 - 0
src/prefs.cc

@@ -363,6 +363,8 @@ PrefPtr PREF_ENABLE_COLOR = makePref("enable-color");
 PrefPtr PREF_RPC_SECRET = makePref("rpc-secret");
 // values: 1*digit
 PrefPtr PREF_DSCP = makePref("dscp");
+// values: true | false
+PrefPtr PREF_PAUSE_METADATA = makePref("pause-metadata");
 
 /**
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -300,6 +300,8 @@ extern PrefPtr PREF_ENABLE_COLOR;
 extern PrefPtr PREF_RPC_SECRET;
 // values: 1*digit
 extern PrefPtr PREF_DSCP;
+// values: true | false
+extern PrefPtr PREF_PAUSE_METADATA;
 
 /**
  * FTP related preferences

+ 11 - 0
src/usage_text.h

@@ -980,3 +980,14 @@
     "                              commonly used values from RFC, network vendors'\n" \
     "                              documentation, Wikipedia or any other source,\n" \
     "                              use them as they are.")
+#define TEXT_PAUSE_METADATA                  \
+  _(" --pause-metadata[=true|false]\n"       \
+    "                              Pause downloads created as a result of metadata\n" \
+    "                              download. There are 3 types of metadata\n" \
+    "                              downloads in aria2: (1) downloading .torrent\n" \
+    "                              file. (2) downloading torrent metadata using\n" \
+    "                              magnet link. (3) downloading metalink file.\n" \
+    "                              These metadata downloads will generate downloads\n" \
+    "                              using their metadata. This option pauses these\n" \
+    "                              subsequent downloads. This option is effective\n" \
+    "                              only when --enable-rpc=true is given.")