mirror of https://github.com/aria2/aria2
2009-05-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that read-only file with wrong file size will cause error because it cannot be truncated to the correct size. Now if file size is different than the expected one, re-open file in writable mode. * src/AbstractSingleDiskAdaptor.cc * src/AbstractSingleDiskAdaptor.h * src/BtCheckIntegrityEntry.cc * src/DiskAdaptor.h * src/MultiDiskAdaptor.h * src/RequestGroup.ccpull/1/head
parent
ee229c6f00
commit
eeece05063
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2009-05-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Fixed the bug that read-only file with wrong file size will cause
|
||||
error because it cannot be truncated to the correct size. Now if
|
||||
file size is different than the expected one, re-open file in
|
||||
writable mode.
|
||||
* src/AbstractSingleDiskAdaptor.cc
|
||||
* src/AbstractSingleDiskAdaptor.h
|
||||
* src/BtCheckIntegrityEntry.cc
|
||||
* src/DiskAdaptor.h
|
||||
* src/MultiDiskAdaptor.h
|
||||
* src/RequestGroup.cc
|
||||
|
||||
2009-05-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Fixed the bug that with --check-integrity option aria2 reports
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
AbstractSingleDiskAdaptor::AbstractSingleDiskAdaptor():totalLength(0) {}
|
||||
AbstractSingleDiskAdaptor::AbstractSingleDiskAdaptor():
|
||||
totalLength(0), _readOnly(false) {}
|
||||
|
||||
AbstractSingleDiskAdaptor::~AbstractSingleDiskAdaptor() {}
|
||||
|
||||
|
@ -126,11 +127,13 @@ bool AbstractSingleDiskAdaptor::directIOAllowed() const
|
|||
void AbstractSingleDiskAdaptor::enableReadOnly()
|
||||
{
|
||||
diskWriter->enableReadOnly();
|
||||
_readOnly = true;
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::disableReadOnly()
|
||||
{
|
||||
diskWriter->disableReadOnly();
|
||||
_readOnly = false;
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::cutTrailingGarbage()
|
||||
|
|
|
@ -46,6 +46,7 @@ class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
|||
protected:
|
||||
SharedHandle<DiskWriter> diskWriter;
|
||||
uint64_t totalLength;
|
||||
bool _readOnly;
|
||||
public:
|
||||
AbstractSingleDiskAdaptor();
|
||||
|
||||
|
@ -84,6 +85,8 @@ public:
|
|||
// Make sure that DiskWriter is set before calling this function.
|
||||
virtual void disableReadOnly();
|
||||
|
||||
virtual bool isReadOnlyEnabled() const { return _readOnly; }
|
||||
|
||||
virtual void cutTrailingGarbage();
|
||||
|
||||
virtual std::string getFilePath() = 0;
|
||||
|
|
|
@ -51,11 +51,14 @@ BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
|
|||
void BtCheckIntegrityEntry::onDownloadIncomplete(std::deque<Command*>& commands,
|
||||
DownloadEngine* e)
|
||||
{
|
||||
// Now reopen DiskAdaptor with read only disabled.
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->closeFile();
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->disableReadOnly();
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->openFile();
|
||||
|
||||
const SharedHandle<DiskAdaptor>& diskAdaptor =
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||
if(diskAdaptor->isReadOnlyEnabled()) {
|
||||
// Now reopen DiskAdaptor with read only disabled.
|
||||
diskAdaptor->closeFile();
|
||||
diskAdaptor->disableReadOnly();
|
||||
diskAdaptor->openFile();
|
||||
}
|
||||
SharedHandle<BtFileAllocationEntry> entry
|
||||
(new BtFileAllocationEntry(_requestGroup));
|
||||
proceedFileAllocation(commands, entry, e);
|
||||
|
|
|
@ -100,6 +100,8 @@ public:
|
|||
|
||||
virtual void disableReadOnly() {}
|
||||
|
||||
virtual bool isReadOnlyEnabled() const { return false; }
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -155,6 +155,8 @@ public:
|
|||
|
||||
virtual void disableReadOnly();
|
||||
|
||||
virtual bool isReadOnlyEnabled() const { return _readOnly; }
|
||||
|
||||
void setPieceLength(size_t pieceLength) {
|
||||
this->pieceLength = pieceLength;
|
||||
}
|
||||
|
|
|
@ -311,7 +311,20 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
|||
}
|
||||
}
|
||||
_progressInfoFile = progressInfoFile;
|
||||
|
||||
{
|
||||
uint64_t actualFileSize = _pieceStorage->getDiskAdaptor()->size();
|
||||
if(actualFileSize != btContext->getTotalLength()) {
|
||||
// Re-open file in writable mode to allow the program
|
||||
// truncate the file to the specified length
|
||||
_logger->debug("File size not match. Re-open file in writable mode."
|
||||
" Expected:%s Actual:%s",
|
||||
Util::uitos(btContext->getTotalLength()).c_str(),
|
||||
Util::uitos(actualFileSize).c_str());
|
||||
_pieceStorage->getDiskAdaptor()->closeFile();
|
||||
_pieceStorage->getDiskAdaptor()->disableReadOnly();
|
||||
_pieceStorage->getDiskAdaptor()->openFile();
|
||||
}
|
||||
}
|
||||
if(!btContext->isPrivate() && _option->getAsBool(PREF_ENABLE_DHT)) {
|
||||
std::deque<Command*> commands;
|
||||
DHTSetup().setup(commands, e, _option);
|
||||
|
@ -371,7 +384,7 @@ void RequestGroup::processCheckIntegrityEntry(std::deque<Command*>& commands,
|
|||
if(e->option->getAsBool(PREF_CHECK_INTEGRITY) &&
|
||||
entry->isValidationReady()) {
|
||||
entry->initValidator();
|
||||
entry->cutTrailingGarbage();
|
||||
entry->cutTrailingGarbage();
|
||||
e->_checkIntegrityMan->pushEntry(entry);
|
||||
} else
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
|
Loading…
Reference in New Issue