diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-09-01 10:47:42 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-09-01 10:47:42 +0000 |
| commit | cb083125821acfcfbb1e4a4d8ecbd81829df7981 (patch) | |
| tree | 8529f8332f4994b83699b6aaa8b8e42b85c0df00 /src | |
| parent | 752c85fd2f05f9e71a10d30d05e1c21a0e4dadf8 (diff) | |
2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed chunk checksum validation cannot detect trailing garbage
data.
BUG#2074141
* src/AbstractSingleDiskAdaptor.cc
* src/AbstractSingleDiskAdaptor.h
* src/CheckIntegrityEntry.cc
* src/CheckIntegrityEntry.h
* src/DiskAdaptor.h
* src/MultiDiskAdaptor.cc
* src/MultiDiskAdaptor.h
* src/RequestGroup.cc
* test/DirectDiskAdaptorTest.cc
* test/MultiDiskAdaptorTest.cc
* test/TestUtil.cc
* test/TestUtil.h
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractSingleDiskAdaptor.cc | 7 | ||||
| -rw-r--r-- | src/AbstractSingleDiskAdaptor.h | 2 | ||||
| -rw-r--r-- | src/CheckIntegrityEntry.cc | 8 | ||||
| -rw-r--r-- | src/CheckIntegrityEntry.h | 2 | ||||
| -rw-r--r-- | src/DiskAdaptor.h | 7 | ||||
| -rw-r--r-- | src/MultiDiskAdaptor.cc | 13 | ||||
| -rw-r--r-- | src/MultiDiskAdaptor.h | 2 | ||||
| -rw-r--r-- | src/RequestGroup.cc | 1 |
8 files changed, 42 insertions, 0 deletions
diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index 81fcdf4c..0114a646 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -110,6 +110,13 @@ bool AbstractSingleDiskAdaptor::directIOAllowed() const { return diskWriter->directIOAllowed(); } + +void AbstractSingleDiskAdaptor::cutTrailingGarbage() +{ + if(File(getFilePath()).size() > totalLength) { + diskWriter->truncate(totalLength); + } +} void AbstractSingleDiskAdaptor::setDiskWriter(const DiskWriterHandle& diskWriter) { diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h index ac3668b4..aa776a28 100644 --- a/src/AbstractSingleDiskAdaptor.h +++ b/src/AbstractSingleDiskAdaptor.h @@ -78,6 +78,8 @@ public: virtual bool directIOAllowed() const; + virtual void cutTrailingGarbage(); + void setDiskWriter(const SharedHandle<DiskWriter>& diskWriter); SharedHandle<DiskWriter> getDiskWriter() const; diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index e961d9b7..5bfec8c5 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -34,6 +34,9 @@ /* copyright --> */ #include "CheckIntegrityEntry.h" #include "IteratableValidator.h" +#include "RequestGroup.h" +#include "PieceStorage.h" +#include "DiskAdaptor.h" namespace aria2 { @@ -72,4 +75,9 @@ bool CheckIntegrityEntry::finished() return _validator->finished(); } +void CheckIntegrityEntry::cutTrailingGarbage() +{ + _requestGroup->getPieceStorage()->getDiskAdaptor()->cutTrailingGarbage(); +} + } // namespace aria2 diff --git a/src/CheckIntegrityEntry.h b/src/CheckIntegrityEntry.h index c8042e0b..300c7536 100644 --- a/src/CheckIntegrityEntry.h +++ b/src/CheckIntegrityEntry.h @@ -70,6 +70,8 @@ public: virtual void onDownloadIncomplete(std::deque<Command*>& commands, DownloadEngine* e) = 0; + + void cutTrailingGarbage(); }; typedef SharedHandle<CheckIntegrityEntry> CheckIntegrityEntryHandle; diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index df4acf1e..ddf562b7 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -96,6 +96,13 @@ public: virtual void enableDirectIO() {} virtual void disableDirectIO() {} + + // Assumed each file length is stored in fileEntries or DiskAdaptor knows it. + // If each actual file's length is larger than that, truncate file to that + // length. + // Call one of openFile/openExistingFile/initAndOpenFile before calling this + // function. + virtual void cutTrailingGarbage() = 0; }; typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle; diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index cf74b4b9..9ce2ecb9 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -442,6 +442,19 @@ void MultiDiskAdaptor::disableDirectIO() } } +void MultiDiskAdaptor::cutTrailingGarbage() +{ + for(std::deque<SharedHandle<DiskWriterEntry> >::const_iterator i = + diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) { + uint64_t length = (*i)->getFileEntry()->getLength(); + if(File((*i)->getFilePath(_cachedTopDirPath)).size() > length) { + // We need open file before calling DiskWriter::truncate(uint64_t) + openIfNot(*i, &DiskWriterEntry::openFile, _cachedTopDirPath); + (*i)->getDiskWriter()->truncate(length); + } + } +} + void MultiDiskAdaptor::setMaxOpenFiles(size_t maxOpenFiles) { _maxOpenFiles = maxOpenFiles; diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h index 5a8b2484..cabd1f20 100644 --- a/src/MultiDiskAdaptor.h +++ b/src/MultiDiskAdaptor.h @@ -181,6 +181,8 @@ public: _directIOAllowed = b; } + virtual void cutTrailingGarbage(); + void setMaxOpenFiles(size_t maxOpenFiles); }; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 05a18625..7b5d49ca 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -315,6 +315,7 @@ void RequestGroup::processCheckIntegrityEntry(std::deque<Command*>& commands, if(e->option->getAsBool(PREF_CHECK_INTEGRITY) && entry->isValidationReady()) { entry->initValidator(); + entry->cutTrailingGarbage(); CheckIntegrityCommand* command = new CheckIntegrityCommand(CUIDCounterSingletonHolder::instance()->newID(), this, e, entry); commands.push_back(command); |
