Ver Fonte

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

	Run whole checksum check when download file name and size are
	determined and download is already completed. Related to r2221.
	Guarded ENABLE_MESSAGE_DIGEST where necessary.
	* src/AbstractCommand.cc
	* src/RequestGroup.cc
	* src/message.h
Tatsuhiro Tsujikawa há 15 anos atrás
pai
commit
3a3511ee28
4 ficheiros alterados com 35 adições e 3 exclusões
  1. 9 0
      ChangeLog
  2. 20 0
      src/AbstractCommand.cc
  3. 4 3
      src/RequestGroup.cc
  4. 2 0
      src/message.h

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2010-06-23  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Run whole checksum check when download file name and size are
+	determined and download is already completed. Related to r2221.
+	Guarded ENABLE_MESSAGE_DIGEST where necessary.
+	* src/AbstractCommand.cc
+	* src/RequestGroup.cc
+	* src/message.h
+
 2010-06-23  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Made log and log-level option modifiable using

+ 20 - 0
src/AbstractCommand.cc

@@ -68,6 +68,9 @@
 #include "NameResolver.h"
 #include "ServerStatMan.h"
 #include "FileAllocationEntry.h"
+#ifdef ENABLE_MESSAGE_DIGEST
+# include "ChecksumCheckIntegrityEntry.h"
+#endif // ENABLE_MESSAGE_DIGEST
 
 namespace aria2 {
 
@@ -719,6 +722,23 @@ std::string AbstractCommand::resolveHostname
 // function call.
 void AbstractCommand::prepareForNextAction(Command* nextCommand)
 {
+#ifdef ENABLE_MESSAGE_DIGEST
+  if(requestGroup_->downloadFinished() &&
+     getDownloadContext()->isChecksumVerificationNeeded()) {
+    if(getLogger()->info()) {
+      getLogger()->info(MSG_HASH_CHECK_NOT_DONE);
+    }
+    SharedHandle<CheckIntegrityEntry> entry
+      (new ChecksumCheckIntegrityEntry(requestGroup_));
+    if(entry->isValidationReady()) {
+      delete nextCommand;
+      entry->initValidator();
+      entry->cutTrailingGarbage();
+      e_->getCheckIntegrityMan()->pushEntry(entry);
+      return;
+    }
+  }
+#endif // ENABLE_MESSAGE_DIGEST
   SharedHandle<CheckIntegrityEntry> entry
     (new StreamCheckIntegrityEntry(requestGroup_, nextCommand));
 

+ 4 - 3
src/RequestGroup.cc

@@ -395,11 +395,11 @@ void RequestGroup::createInitialCommand
                         downloadContext_->getBasePath().c_str());
       } else {
         loadAndOpenFile(infoFile);
+#ifdef ENABLE_MESSAGE_DIGEST
         if(downloadFinished() &&
            downloadContext_->isChecksumVerificationNeeded()) {
           if(logger_->info()) {
-            logger_->info("File has already been downloaded but hash check has"
-                          " not been done yet.");
+            logger_->info(MSG_HASH_CHECK_NOT_DONE);
           }
           SharedHandle<CheckIntegrityEntry> entry
             (new ChecksumCheckIntegrityEntry(this));
@@ -407,9 +407,10 @@ void RequestGroup::createInitialCommand
             entry->initValidator();
             entry->cutTrailingGarbage();
             e->getCheckIntegrityMan()->pushEntry(entry);
+            return;
           }
-          return;
         }
+#endif // ENABLE_MESSAGE_DIGEST
         SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
           (new StreamCheckIntegrityEntry(this));
         processCheckIntegrityEntry(commands, checkIntegrityEntry, e);

+ 2 - 0
src/message.h

@@ -188,6 +188,8 @@
 #define MSG_METADATA_NOT_SAVED _("Saving metadata as %s failed. Maybe file" \
                                  " already exists.")
 #define MSG_DIR_TRAVERSAL_DETECTED _("Detected directory traversal directive in %s")
+#define MSG_HASH_CHECK_NOT_DONE                                         \
+  "File has already been downloaded but hash check has not been done yet."
 
 #define EX_TIME_OUT _("Timeout.")
 #define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")