فهرست منبع

2010-06-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed that bug that when aria2 is stopped before whole hash
	check(not piece hash check) is done, aria2 reports its file is
	downloaded successfully. It should report the download is
	in-progress and next invocation of aria2 should check hash.
	* src/ChecksumCheckIntegrityEntry.cc
	* src/DownloadCommand.cc
	* src/DownloadContext.cc
	* src/DownloadContext.h
	* src/RequestGroup.cc
	* src/RequestGroupMan.cc
Tatsuhiro Tsujikawa 15 سال پیش
والد
کامیت
d787906b34
7فایلهای تغییر یافته به همراه57 افزوده شده و 5 حذف شده
  1. 13 0
      ChangeLog
  2. 3 1
      src/ChecksumCheckIntegrityEntry.cc
  3. 1 1
      src/DownloadCommand.cc
  4. 8 0
      src/DownloadContext.cc
  5. 11 0
      src/DownloadContext.h
  6. 17 1
      src/RequestGroup.cc
  7. 4 2
      src/RequestGroupMan.cc

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2010-06-22  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed that bug that when aria2 is stopped before whole hash
+	check(not piece hash check) is done, aria2 reports its file is
+	downloaded successfully. It should report the download is
+	in-progress and next invocation of aria2 should check hash.
+	* src/ChecksumCheckIntegrityEntry.cc
+	* src/DownloadCommand.cc
+	* src/DownloadContext.cc
+	* src/DownloadContext.h
+	* src/RequestGroup.cc
+	* src/RequestGroupMan.cc
+
 2010-06-21  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Code cleanup

+ 3 - 1
src/ChecksumCheckIntegrityEntry.cc

@@ -68,7 +68,9 @@ void ChecksumCheckIntegrityEntry::initValidator()
 void
 ChecksumCheckIntegrityEntry::onDownloadFinished
 (std::vector<Command*>& commands, DownloadEngine* e)
-{}
+{
+  getRequestGroup()->getDownloadContext()->setChecksumVerified(true);
+}
 
 void
 ChecksumCheckIntegrityEntry::onDownloadIncomplete

+ 1 - 1
src/DownloadCommand.cc

@@ -297,7 +297,7 @@ bool DownloadCommand::prepareForNextSegment() {
         (new ChecksumCheckIntegrityEntry(getRequestGroup()));
       if(entry->isValidationReady()) {
         entry->initValidator();
-        // TODO do we need cuttrailinggarbage here?
+        entry->cutTrailingGarbage();
         getDownloadEngine()->getCheckIntegrityMan()->pushEntry(entry);
       }
     }

+ 8 - 0
src/DownloadContext.cc

@@ -47,6 +47,7 @@ namespace aria2 {
 DownloadContext::DownloadContext():
   dir_(A2STR::DOT_C),
   pieceLength_(0),
+  checksumVerified_(false),
   knowsTotalLength_(true),
   ownerRequestGroup_(0),
   downloadStartTime_(0),
@@ -57,6 +58,7 @@ DownloadContext::DownloadContext(size_t pieceLength,
                                  const std::string& path):
   dir_(A2STR::DOT_C),
   pieceLength_(pieceLength),
+  checksumVerified_(false),
   knowsTotalLength_(true),
   ownerRequestGroup_(0),
   downloadStartTime_(0),
@@ -205,4 +207,10 @@ const std::string& DownloadContext::getBasePath() const
   }
 }
 
+bool DownloadContext::isChecksumVerificationNeeded() const
+{
+  return pieceHashAlgo_.empty() &&
+    !checksum_.empty() && !checksumHashAlgo_.empty() && !checksumVerified_;
+}
+
 } // namespace aria2

+ 11 - 0
src/DownloadContext.h

@@ -71,6 +71,8 @@ private:
 
   std::string checksumHashAlgo_;
 
+  bool checksumVerified_;
+
   std::string basePath_;
 
   bool knowsTotalLength_;
@@ -200,6 +202,15 @@ public:
   // this function.
   void setFilePathWithIndex(size_t index, const std::string& path);
 
+  // Returns true if hash check(whole file hash, not piece hash) is
+  // need to be done
+  bool isChecksumVerificationNeeded() const;
+
+  void setChecksumVerified(bool f)
+  {
+    checksumVerified_ = f;
+  }
+
   void setAttribute
   (const std::string& key, const SharedHandle<ContextAttribute>& value);
 

+ 17 - 1
src/RequestGroup.cc

@@ -80,6 +80,7 @@
 #include "Segment.h"
 #ifdef ENABLE_MESSAGE_DIGEST
 # include "CheckIntegrityCommand.h"
+# include "ChecksumCheckIntegrityEntry.h"
 #endif // ENABLE_MESSAGE_DIGEST
 #ifdef ENABLE_BITTORRENT
 # include "bittorrent_helper.h"
@@ -173,7 +174,7 @@ bool RequestGroup::allDownloadFinished() const
 
 downloadresultcode::RESULT RequestGroup::downloadResult() const
 {
-  if (downloadFinished())
+  if(downloadFinished() && !downloadContext_->isChecksumVerificationNeeded())
     return downloadresultcode::FINISHED;
   else {
     if (lastUriResult_.isNull()) {
@@ -394,6 +395,21 @@ void RequestGroup::createInitialCommand
                         downloadContext_->getBasePath().c_str());
       } else {
         loadAndOpenFile(infoFile);
+        if(downloadFinished() &&
+           downloadContext_->isChecksumVerificationNeeded()) {
+          if(logger_->info()) {
+            logger_->info("File has already been downloaded but hash check has"
+                          " not been done yet.");
+          }
+          SharedHandle<CheckIntegrityEntry> entry
+            (new ChecksumCheckIntegrityEntry(this));
+          if(entry->isValidationReady()) {
+            entry->initValidator();
+            entry->cutTrailingGarbage();
+            e->getCheckIntegrityMan()->pushEntry(entry);
+          }
+          return;
+        }
         SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
           (new StreamCheckIntegrityEntry(this));
         processCheckIntegrityEntry(commands, checkIntegrityEntry, e);

+ 4 - 2
src/RequestGroupMan.cc

@@ -365,7 +365,8 @@ public:
       }
       try {
         group->closeFile();
-        if(group->downloadFinished()) {
+        if(group->downloadFinished() &&
+           !group->getDownloadContext()->isChecksumVerificationNeeded()) {
           group->setPauseRequested(false);
           group->applyLastModifiedTimeToLocalFiles();
           group->reportDownloadFinished();
@@ -575,7 +576,8 @@ void RequestGroupMan::save()
 {
   for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
         requestGroups_.begin(), eoi = requestGroups_.end(); itr != eoi; ++itr) {
-    if((*itr)->allDownloadFinished()) {
+    if((*itr)->allDownloadFinished() && 
+       !(*itr)->getDownloadContext()->isChecksumVerificationNeeded()) {
       (*itr)->removeControlFile();
     } else {
       try {