Browse Source

Save control file early

Tatsuhiro Tsujikawa 8 years ago
parent
commit
bfc54d0b9a
2 changed files with 17 additions and 0 deletions
  1. 7 0
      src/BtFileAllocationEntry.cc
  2. 10 0
      src/StreamFileAllocationEntry.cc

+ 7 - 0
src/BtFileAllocationEntry.cc

@@ -81,6 +81,13 @@ void BtFileAllocationEntry::prepareForNextAction(
                                          std::end(fileEntries))) {
       rg->createNextCommandWithAdj(commands, e, 0);
     }
+
+    try {
+      rg->saveControlFile();
+    }
+    catch (RecoverableException& e) {
+      A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+    }
   }
   else {
 #ifdef __MINGW32__

+ 10 - 0
src/StreamFileAllocationEntry.cc

@@ -46,6 +46,7 @@
 #include "FileEntry.h"
 #include "PieceStorage.h"
 #include "DiskAdaptor.h"
+#include "LogFactory.h"
 
 namespace aria2 {
 
@@ -97,6 +98,15 @@ void StreamFileAllocationEntry::prepareForNextAction(
   else {
     rg->createNextCommandWithAdj(commands, e, 0);
   }
+
+  if (!rg->allDownloadFinished()) {
+    try {
+      rg->saveControlFile();
+    }
+    catch (RecoverableException& e) {
+      A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
+    }
+  }
 }
 
 } // namespace aria2