Prechádzať zdrojové kódy

Added --force-save option.

--force-save option saves download with --save-session option even if
the download is completed or removed. This may be useful to save
BitTorrent seeding which is recognized as completed state.  The
default value is false.
Tatsuhiro Tsujikawa 13 rokov pred
rodič
commit
e0dcb942b2
5 zmenil súbory, kde vykonal 29 pridanie a 1 odobranie
  1. 13 0
      src/OptionHandlerFactory.cc
  2. 7 1
      src/SessionSerializer.cc
  3. 2 0
      src/prefs.cc
  4. 2 0
      src/prefs.h
  5. 5 0
      src/usage_text.h

+ 13 - 0
src/OptionHandlerFactory.cc

@@ -370,6 +370,19 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
     op->setChangeOptionForReserved(true);
     handlers.push_back(op);
   }
+  {
+    OptionHandler* op(new BooleanOptionHandler
+                      (PREF_FORCE_SAVE,
+                       TEXT_FORCE_SAVE,
+                       A2_V_FALSE,
+                       OptionHandler::OPT_ARG));
+    op->addTag(TAG_ADVANCED);
+    op->setInitialOption(true);
+    op->setChangeOption(true);
+    op->setChangeGlobalOption(true);
+    op->setChangeOptionForReserved(true);
+    handlers.push_back(op);
+  }
   {
     OptionHandler* op(new BooleanOptionHandler
                       (PREF_FORCE_SEQUENTIAL,

+ 7 - 1
src/SessionSerializer.cc

@@ -159,7 +159,13 @@ bool SessionSerializer::save(BufferedFile& fp) const
         results.begin(), eoi = results.end(); itr != eoi; ++itr) {
     if((*itr)->result == error_code::FINISHED ||
        (*itr)->result == error_code::REMOVED) {
-      continue;
+      if((*itr)->option->getAsBool(PREF_FORCE_SAVE)) {
+        if(!writeDownloadResult(fp, metainfoCache, *itr)) {
+          return false;
+        }
+      } else {
+        continue;
+      }
     } else if((*itr)->result == error_code::IN_PROGRESS) {
       if(saveInProgress_) {
         if(!writeDownloadResult(fp, metainfoCache, *itr)) {

+ 2 - 0
src/prefs.cc

@@ -336,6 +336,8 @@ const Pref* PREF_CHECKSUM = makePref("checksum");
 const Pref* PREF_STOP_WITH_PROCESS = makePref("stop-with-process");
 // value: true | false
 const Pref* PREF_ENABLE_MMAP = makePref("enable-mmap");
+// value: true | false
+const Pref* PREF_FORCE_SAVE = makePref("force-save");
 
 /**
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -279,6 +279,8 @@ extern const Pref* PREF_CHECKSUM;
 extern const Pref* PREF_STOP_WITH_PROCESS;
 // value: true | false
 extern const Pref* PREF_ENABLE_MMAP;
+// value: true | false
+extern const Pref* PREF_FORCE_SAVE;
 
 /**
  * FTP related preferences

+ 5 - 0
src/usage_text.h

@@ -909,3 +909,8 @@
     "                              downloads added by aria2.addTorrent or\n" \
     "                              aria2.addMetalink will not be saved by\n" \
     "                              --save-session option.")
+#define TEXT_FORCE_SAVE                         \
+  _(" --force-save[=true|false]    Save download with --save-session option even\n" \
+    "                              if the download is completed or removed. This\n" \
+    "                              may be useful to save BitTorrent seeding which\n" \
+    "                              is recognized as completed state.")