summaryrefslogtreecommitdiff
path: root/src/IteratableChunkChecksumValidator.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-05-03 06:26:44 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-05-03 06:26:44 +0000
commitee229c6f00a0a01b99e37d91c14060a29d41a3a6 (patch)
treef1c7f4e174bf0fe9942e5427e953b9d3328aebc2 /src/IteratableChunkChecksumValidator.cc
parentd0b485cba0c2f83a0db3a2e6300a95a3d75d75b7 (diff)
2009-05-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that with --check-integrity option aria2 reports downloaded file size is 0 even if some parts of file is correctly downloaded. This bug is reproducible for the download that a file includes last piece is missing. This bug doesn't reveal for single-torrent with file allocation on. * src/IteratableChecksumValidator.cc * test/IteratableChecksumValidatorTest.cc
Diffstat (limited to 'src/IteratableChunkChecksumValidator.cc')
-rw-r--r--src/IteratableChunkChecksumValidator.cc27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/IteratableChunkChecksumValidator.cc b/src/IteratableChunkChecksumValidator.cc
index dc03fc67..d28883df 100644
--- a/src/IteratableChunkChecksumValidator.cc
+++ b/src/IteratableChunkChecksumValidator.cc
@@ -83,23 +83,22 @@ void IteratableChunkChecksumValidator::validateChunk()
std::string actualChecksum;
try {
actualChecksum = calculateActualChecksum();
+ if(actualChecksum == _dctx->getPieceHashes()[_currentIndex]) {
+ _bitfield->setBit(_currentIndex);
+ } else {
+ _logger->info(EX_INVALID_CHUNK_CHECKSUM,
+ _currentIndex,
+ Util::itos(getCurrentOffset(), true).c_str(),
+ _dctx->getPieceHashes()[_currentIndex].c_str(),
+ actualChecksum.c_str());
+ _bitfield->unsetBit(_currentIndex);
+ }
} catch(RecoverableException& ex) {
_logger->debug("Caught exception while validating piece index=%d. Some part of file may be missing. Continue operation.", ex, _currentIndex);
_bitfield->unsetBit(_currentIndex);
- _currentIndex++;
- return;
}
- if(actualChecksum == _dctx->getPieceHashes()[_currentIndex]) {
- _bitfield->setBit(_currentIndex);
- } else {
- _logger->info(EX_INVALID_CHUNK_CHECKSUM,
- _currentIndex,
- Util::itos(getCurrentOffset(), true).c_str(),
- _dctx->getPieceHashes()[_currentIndex].c_str(),
- actualChecksum.c_str());
- _bitfield->unsetBit(_currentIndex);
- }
- _currentIndex++;
+
+ ++_currentIndex;
if(finished()) {
_pieceStorage->setBitfield(_bitfield->getBitfield(), _bitfield->getBitfieldLength());
}
@@ -152,7 +151,7 @@ std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length
while(curoffset < max) {
size_t r = _pieceStorage->getDiskAdaptor()->readData(_buffer, BUFSIZE,
curoffset);
- if(r == 0) {
+ if(r == 0 || r < static_cast<size_t>(woffset)) {
throw DlAbortEx
(StringFormat(EX_FILE_READ, _dctx->getActualBasePath().c_str(),
strerror(errno)).str());