Переглянути джерело

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

+ 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>
 2010-06-21  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 
 	Code cleanup
 	Code cleanup

+ 3 - 1
src/ChecksumCheckIntegrityEntry.cc

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

+ 1 - 1
src/DownloadCommand.cc

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

+ 8 - 0
src/DownloadContext.cc

@@ -47,6 +47,7 @@ namespace aria2 {
 DownloadContext::DownloadContext():
 DownloadContext::DownloadContext():
   dir_(A2STR::DOT_C),
   dir_(A2STR::DOT_C),
   pieceLength_(0),
   pieceLength_(0),
+  checksumVerified_(false),
   knowsTotalLength_(true),
   knowsTotalLength_(true),
   ownerRequestGroup_(0),
   ownerRequestGroup_(0),
   downloadStartTime_(0),
   downloadStartTime_(0),
@@ -57,6 +58,7 @@ DownloadContext::DownloadContext(size_t pieceLength,
                                  const std::string& path):
                                  const std::string& path):
   dir_(A2STR::DOT_C),
   dir_(A2STR::DOT_C),
   pieceLength_(pieceLength),
   pieceLength_(pieceLength),
+  checksumVerified_(false),
   knowsTotalLength_(true),
   knowsTotalLength_(true),
   ownerRequestGroup_(0),
   ownerRequestGroup_(0),
   downloadStartTime_(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
 } // namespace aria2

+ 11 - 0
src/DownloadContext.h

@@ -71,6 +71,8 @@ private:
 
 
   std::string checksumHashAlgo_;
   std::string checksumHashAlgo_;
 
 
+  bool checksumVerified_;
+
   std::string basePath_;
   std::string basePath_;
 
 
   bool knowsTotalLength_;
   bool knowsTotalLength_;
@@ -200,6 +202,15 @@ public:
   // this function.
   // this function.
   void setFilePathWithIndex(size_t index, const std::string& path);
   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
   void setAttribute
   (const std::string& key, const SharedHandle<ContextAttribute>& value);
   (const std::string& key, const SharedHandle<ContextAttribute>& value);
 
 

+ 17 - 1
src/RequestGroup.cc

@@ -80,6 +80,7 @@
 #include "Segment.h"
 #include "Segment.h"
 #ifdef ENABLE_MESSAGE_DIGEST
 #ifdef ENABLE_MESSAGE_DIGEST
 # include "CheckIntegrityCommand.h"
 # include "CheckIntegrityCommand.h"
+# include "ChecksumCheckIntegrityEntry.h"
 #endif // ENABLE_MESSAGE_DIGEST
 #endif // ENABLE_MESSAGE_DIGEST
 #ifdef ENABLE_BITTORRENT
 #ifdef ENABLE_BITTORRENT
 # include "bittorrent_helper.h"
 # include "bittorrent_helper.h"
@@ -173,7 +174,7 @@ bool RequestGroup::allDownloadFinished() const
 
 
 downloadresultcode::RESULT RequestGroup::downloadResult() const
 downloadresultcode::RESULT RequestGroup::downloadResult() const
 {
 {
-  if (downloadFinished())
+  if(downloadFinished() && !downloadContext_->isChecksumVerificationNeeded())
     return downloadresultcode::FINISHED;
     return downloadresultcode::FINISHED;
   else {
   else {
     if (lastUriResult_.isNull()) {
     if (lastUriResult_.isNull()) {
@@ -394,6 +395,21 @@ void RequestGroup::createInitialCommand
                         downloadContext_->getBasePath().c_str());
                         downloadContext_->getBasePath().c_str());
       } else {
       } else {
         loadAndOpenFile(infoFile);
         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
         SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
           (new StreamCheckIntegrityEntry(this));
           (new StreamCheckIntegrityEntry(this));
         processCheckIntegrityEntry(commands, checkIntegrityEntry, e);
         processCheckIntegrityEntry(commands, checkIntegrityEntry, e);

+ 4 - 2
src/RequestGroupMan.cc

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