Fix bug that file allocation=trunc get stuck with Windows symlink

pull/498/head
Tatsuhiro Tsujikawa 2015-11-22 00:36:43 +09:00
parent 2eb92bc4be
commit c2157e608e
1 changed files with 22 additions and 8 deletions

View File

@ -42,6 +42,7 @@
#endif // HAVE_SOME_FALLOCATE #endif // HAVE_SOME_FALLOCATE
#include "DiskWriter.h" #include "DiskWriter.h"
#include "DefaultDiskWriterFactory.h" #include "DefaultDiskWriterFactory.h"
#include "LogFactory.h"
namespace aria2 { namespace aria2 {
@ -59,18 +60,26 @@ MultiFileAllocationIterator::~MultiFileAllocationIterator() {
void MultiFileAllocationIterator::allocateChunk() void MultiFileAllocationIterator::allocateChunk()
{ {
while((!fileAllocationIterator_ || if (fileAllocationIterator_) {
fileAllocationIterator_->finished()) && if (!fileAllocationIterator_->finished()) {
entryItr_ != std::end(diskAdaptor_->getDiskWriterEntries())) { fileAllocationIterator_->allocateChunk();
return;
}
if (diskWriter_) { if (diskWriter_) {
diskWriter_->closeFile(); diskWriter_->closeFile();
diskWriter_.reset(); diskWriter_.reset();
} }
fileAllocationIterator_.reset(); fileAllocationIterator_.reset();
++entryItr_;
}
while(entryItr_ != std::end(diskAdaptor_->getDiskWriterEntries())) {
if(!(*entryItr_)->getDiskWriter()) { if(!(*entryItr_)->getDiskWriter()) {
++entryItr_; ++entryItr_;
continue; continue;
} }
auto& fileEntry = (*entryItr_)->getFileEntry(); auto& fileEntry = (*entryItr_)->getFileEntry();
// we use dedicated DiskWriter instead of // we use dedicated DiskWriter instead of
// (*entryItr_)->getDiskWriter(). This is because // (*entryItr_)->getDiskWriter(). This is because
@ -84,6 +93,10 @@ void MultiFileAllocationIterator::allocateChunk()
if((*entryItr_)->needsFileAllocation() && if((*entryItr_)->needsFileAllocation() &&
(*entryItr_)->size() < fileEntry->getLength()) { (*entryItr_)->size() < fileEntry->getLength()) {
A2_LOG_INFO(fmt("Allocating file %s: target size=%" PRId64
", current size=%" PRId64,
(*entryItr_)->getFilePath().c_str(),
fileEntry->getLength(), (*entryItr_)->size()));
switch(diskAdaptor_->getFileAllocationMethod()) { switch(diskAdaptor_->getFileAllocationMethod()) {
#ifdef HAVE_SOME_FALLOCATE #ifdef HAVE_SOME_FALLOCATE
case(DiskAdaptor::FILE_ALLOC_FALLOC): case(DiskAdaptor::FILE_ALLOC_FALLOC):
@ -106,14 +119,15 @@ void MultiFileAllocationIterator::allocateChunk()
fileEntry->getLength()); fileEntry->getLength());
break; break;
} }
break; fileAllocationIterator_->allocateChunk();
return;
} }
diskWriter_->closeFile();
diskWriter_.reset();
++entryItr_; ++entryItr_;
} }
if(finished()) {
return;
}
fileAllocationIterator_->allocateChunk();
} }
bool MultiFileAllocationIterator::finished() bool MultiFileAllocationIterator::finished()