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
pull/1/head
Tatsuhiro Tsujikawa 2010-06-22 11:57:31 +00:00
parent 5c1611c702
commit d787906b34
7 changed files with 57 additions and 5 deletions

View File

@ -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

View File

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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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 {