Forráskód Böngészése

Added --gid option

This option sets GID manually. aria2 identifies each download by the
ID called GID. The GID must be hex string of 16 characters, thus
[0-9a-zA-Z] are allowed and leading zeros must not be stripped. The
GID all 0 is reserved and must not be used. The GID must be unique,
otherwise error is reported and the download is not added.  This
option is useful when restoring the sessions saved using
--save-session option. If this option is not used, new GID is
generated by aria2.
Tatsuhiro Tsujikawa 13 éve
szülő
commit
0001f4cfbd
7 módosított fájl, 65 hozzáadás és 7 törlés
  1. 1 0
      doc/xmlrpc/aria2rpc
  2. 9 0
      src/OptionHandlerFactory.cc
  3. 38 7
      src/download_helper.cc
  4. 1 0
      src/main.cc
  5. 2 0
      src/prefs.cc
  6. 2 0
      src/prefs.h
  7. 12 0
      src/usage_text.h

+ 1 - 0
doc/xmlrpc/aria2rpc

@@ -231,6 +231,7 @@ OptionParser.new do |opt|
   opt.on("--save-session FILE"){|val| options["save-session"]=val}
   opt.on("--save-session FILE"){|val| options["save-session"]=val}
   opt.on("--server-stat-of FILE"){|val| options["server-stat-of"]=val}
   opt.on("--server-stat-of FILE"){|val| options["server-stat-of"]=val}
   opt.on("--save-cookies FILE"){|val| options["save-cookies"]=val}
   opt.on("--save-cookies FILE"){|val| options["save-cookies"]=val}
+  opt.on("--gid GID"){|val| options["gid"]=val}
 
 
   opt.on("--server SERVER", "hostname of XML-RPC server. Default: localhost"){|val| options["server"]=val }
   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 }
   opt.on("--port PORT", "port of XML-RPC server. Default: 6800"){|val| options["port"]=val }

+ 9 - 0
src/OptionHandlerFactory.cc

@@ -402,6 +402,15 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_BASIC);
     op->addTag(TAG_BASIC);
     handlers.push_back(op);
     handlers.push_back(op);
   }
   }
+  {
+    OptionHandler* op(new DefaultOptionHandler
+                      (PREF_GID,
+                       TEXT_GID,
+                       NO_DEFAULT_VALUE));
+    op->addTag(TAG_ADVANCED);
+    op->setInitialOption(true);
+    handlers.push_back(op);
+  }
 #ifdef ENABLE_MESSAGE_DIGEST
 #ifdef ENABLE_MESSAGE_DIGEST
   {
   {
     OptionHandler* op(new BooleanOptionHandler
     OptionHandler* op(new BooleanOptionHandler

+ 38 - 7
src/download_helper.cc

@@ -105,6 +105,28 @@ void splitURI(std::vector<std::string>& result,
 }
 }
 } // namespace
 } // namespace
 
 
+namespace {
+SharedHandle<GroupId> getGID(const SharedHandle<Option>& option)
+{
+  SharedHandle<GroupId> gid;
+  if(option->defined(PREF_GID)) {
+    a2_gid_t n;
+    if(GroupId::toNumericId(n, option->get(PREF_GID).c_str()) != 0) {
+      throw DL_ABORT_EX(fmt("%s is invalid for GID.",
+                            option->get(PREF_GID).c_str()));
+    }
+    gid = GroupId::import(n);
+    if(!gid) {
+      throw DL_ABORT_EX(fmt("GID %s is not unique.",
+                            option->get(PREF_GID).c_str()));
+    }
+  } else {
+    gid = GroupId::create();
+  }
+  return gid;
+}
+} // namespace
+
 namespace {
 namespace {
 SharedHandle<RequestGroup> createRequestGroup
 SharedHandle<RequestGroup> createRequestGroup
 (const SharedHandle<Option>& optionTemplate,
 (const SharedHandle<Option>& optionTemplate,
@@ -112,7 +134,7 @@ SharedHandle<RequestGroup> createRequestGroup
  bool useOutOption = false)
  bool useOutOption = false)
 {
 {
   SharedHandle<Option> option = util::copy(optionTemplate);
   SharedHandle<Option> option = util::copy(optionTemplate);
-  SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
+  SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
   SharedHandle<DownloadContext> dctx
   SharedHandle<DownloadContext> dctx
     (new DownloadContext
     (new DownloadContext
      (option->getAsInt(PREF_PIECE_LENGTH),
      (option->getAsInt(PREF_PIECE_LENGTH),
@@ -168,7 +190,7 @@ createBtRequestGroup(const std::string& metaInfoUri,
                      bool adjustAnnounceUri = true)
                      bool adjustAnnounceUri = true)
 {
 {
   SharedHandle<Option> option = util::copy(optionTemplate);
   SharedHandle<Option> option = util::copy(optionTemplate);
-  SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
+  SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
   SharedHandle<DownloadContext> dctx(new DownloadContext());
   SharedHandle<DownloadContext> dctx(new DownloadContext());
   // may throw exception
   // may throw exception
   bittorrent::loadFromMemory(torrent, dctx, option, auxUris,
   bittorrent::loadFromMemory(torrent, dctx, option, auxUris,
@@ -210,7 +232,7 @@ createBtMagnetRequestGroup
  const SharedHandle<Option>& optionTemplate)
  const SharedHandle<Option>& optionTemplate)
 {
 {
   SharedHandle<Option> option = util::copy(optionTemplate);
   SharedHandle<Option> option = util::copy(optionTemplate);
-  SharedHandle<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
+  SharedHandle<RequestGroup> rg(new RequestGroup(getGID(option), option));
   SharedHandle<DownloadContext> dctx
   SharedHandle<DownloadContext> dctx
     (new DownloadContext(METADATA_PIECE_SIZE, 0,
     (new DownloadContext(METADATA_PIECE_SIZE, 0,
                          A2STR::NIL));
                          A2STR::NIL));
@@ -432,10 +454,18 @@ void createRequestGroupForUri
       size_t numSplit = option->getAsInt(PREF_SPLIT);
       size_t numSplit = option->getAsInt(PREF_SPLIT);
       std::vector<std::string> streamURIs;
       std::vector<std::string> streamURIs;
       splitURI(streamURIs, nargs.begin(), strmProtoEnd, numSplit, numIter);
       splitURI(streamURIs, nargs.begin(), strmProtoEnd, numSplit, numIter);
-      SharedHandle<RequestGroup> rg =
-        createRequestGroup(option, streamURIs, true);
-      rg->setNumConcurrentCommand(numSplit);
-      result.push_back(rg);
+      try {
+        SharedHandle<RequestGroup> rg =
+          createRequestGroup(option, streamURIs, true);
+        rg->setNumConcurrentCommand(numSplit);
+        result.push_back(rg);
+      } catch(RecoverableException& e) {
+        if(throwOnError) {
+          throw;
+        } else {
+          A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+        }
+      }
     }
     }
     // process remaining URIs(local metalink, BitTorrent files)
     // process remaining URIs(local metalink, BitTorrent files)
     std::for_each(strmProtoEnd, nargs.end(),
     std::for_each(strmProtoEnd, nargs.end(),
@@ -522,6 +552,7 @@ createMetadataInfoFromFirstFileEntry(const SharedHandle<DownloadContext>& dctx)
 void removeOneshotOption(const SharedHandle<Option>& option)
 void removeOneshotOption(const SharedHandle<Option>& option)
 {
 {
   option->remove(PREF_PAUSE);
   option->remove(PREF_PAUSE);
+  option->remove(PREF_GID);
 }
 }
 
 
 } // namespace aria2
 } // namespace aria2

+ 1 - 0
src/main.cc

@@ -272,6 +272,7 @@ error_code::Value main(int argc, char* argv[])
   op->remove(PREF_SELECT_FILE);
   op->remove(PREF_SELECT_FILE);
   op->remove(PREF_PAUSE);
   op->remove(PREF_PAUSE);
   op->remove(PREF_CHECKSUM);
   op->remove(PREF_CHECKSUM);
+  op->remove(PREF_GID);
   if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty() &&
   if(!op->getAsBool(PREF_ENABLE_RPC) && requestGroups.empty() &&
      !uriListParser) {
      !uriListParser) {
     global::cout()->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);
     global::cout()->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);

+ 2 - 0
src/prefs.cc

@@ -352,6 +352,8 @@ const Pref* PREF_ENABLE_MMAP = makePref("enable-mmap");
 const Pref* PREF_FORCE_SAVE = makePref("force-save");
 const Pref* PREF_FORCE_SAVE = makePref("force-save");
 // value: 1*digit
 // value: 1*digit
 const Pref* PREF_DISK_CACHE = makePref("disk-cache");
 const Pref* PREF_DISK_CACHE = makePref("disk-cache");
+// value: string
+const Pref* PREF_GID = makePref("gid");
 
 
 /**
 /**
  * FTP related preferences
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -287,6 +287,8 @@ extern const Pref* PREF_ENABLE_MMAP;
 extern const Pref* PREF_FORCE_SAVE;
 extern const Pref* PREF_FORCE_SAVE;
 // value: 1*digit
 // value: 1*digit
 extern const Pref* PREF_DISK_CACHE;
 extern const Pref* PREF_DISK_CACHE;
+// value: string
+extern const Pref* PREF_GID;
 
 
 /**
 /**
  * FTP related preferences
  * FTP related preferences

+ 12 - 0
src/usage_text.h

@@ -927,3 +927,15 @@
     "                              cached in memory, we don't need to read them\n" \
     "                              cached in memory, we don't need to read them\n" \
     "                              from the disk.\n"                    \
     "                              from the disk.\n"                    \
     "                              SIZE can include K or M(1K = 1024, 1M = 1024K).")
     "                              SIZE can include K or M(1K = 1024, 1M = 1024K).")
+#define TEXT_GID                                \
+  _(" --gid=GID                    Set GID manually. aria2 identifies each\n" \
+    "                              download by the ID called GID. The GID must be\n" \
+    "                              hex string of 16 characters, thus [0-9a-zA-Z]\n" \
+    "                              are allowed and leading zeros must not be\n" \
+    "                              stripped. The GID all 0 is reserved and must\n" \
+    "                              not be used. The GID must be unique, otherwise\n" \
+    "                              error is reported and the download is not added.\n" \
+    "                              This option is useful when restoring the\n" \
+    "                              sessions saved using --save-session option. If\n" \
+    "                              this option is not used, new GID is generated\n" \
+    "                              by aria2.")