2008-05-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed the bug that the control file(.aria2 file) is not renamed
	according to tryAutoFileRenaming().
	tryAutoFileRenaming() was rewritten so that if both renamed file 
and
	its control file exist, use them and continue download.
	The old implementation didn't take into account of control 
file's
	existence, so basically you couldn't continue download of 
renamed file.
	* src/BtProgressInfoFile.h
	* src/DefaultBtProgressInfoFile.cc
	* src/DefaultBtProgressInfoFile.h
	* src/NullProgressInfoFile.h
	* src/RequestGroup.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/MockBtProgressInfoFile.h
pull/1/head
Tatsuhiro Tsujikawa 2008-05-05 10:10:15 +00:00
parent 6952eef7b6
commit 874714609f
8 changed files with 101 additions and 31 deletions

View File

@ -1,3 +1,19 @@
2008-05-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that the control file(.aria2 file) is not renamed
according to tryAutoFileRenaming().
tryAutoFileRenaming() was rewritten so that if both renamed file and
its control file exist, use them and continue download.
The old implementation didn't take into account of control file's
existence, so basically you couldn't continue download of renamed file.
* src/BtProgressInfoFile.h
* src/DefaultBtProgressInfoFile.cc
* src/DefaultBtProgressInfoFile.h
* src/NullProgressInfoFile.h
* src/RequestGroup.cc
* test/DefaultBtProgressInfoFileTest.cc
* test/MockBtProgressInfoFile.h
2008-05-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Change the default value of --metalink-servers option from `5' to `1'.

View File

@ -54,6 +54,9 @@ public:
virtual void load() = 0;
virtual void removeFile() = 0;
// re-set filename
virtual void updateFilename() = 0;
};
typedef SharedHandle<BtProgressInfoFile> BtProgressInfoFileHandle;

View File

@ -58,19 +58,28 @@
namespace aria2 {
static std::string createFilename(const SharedHandle<DownloadContext>& dctx)
{
return dctx->getActualBasePath()+".aria2";
}
DefaultBtProgressInfoFile::DefaultBtProgressInfoFile(const DownloadContextHandle& dctx,
const PieceStorageHandle& pieceStorage,
const Option* option):
_dctx(dctx),
_pieceStorage(pieceStorage),
_option(option),
_logger(LogFactory::getInstance())
{
_filename = _dctx->getActualBasePath()+".aria2";
}
_logger(LogFactory::getInstance()),
_filename(createFilename(_dctx))
{}
DefaultBtProgressInfoFile::~DefaultBtProgressInfoFile() {}
void DefaultBtProgressInfoFile::updateFilename()
{
_filename = createFilename(_dctx);
}
bool DefaultBtProgressInfoFile::isTorrentDownload()
{
return !dynamic_pointer_cast<BtContext>(_dctx).isNull();

View File

@ -71,6 +71,9 @@ public:
virtual void removeFile();
// re-set filename using current _dctx.
virtual void updateFilename();
};
} // namespace aria2

View File

@ -55,6 +55,8 @@ public:
virtual void load() {}
virtual void removeFile() {}
virtual void updateFilename() {}
};
typedef SharedHandle<NullProgressInfoFile> NullProgressInfoFileHandle;

View File

@ -364,36 +364,44 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF
progressInfoFile->getFilename().c_str(),
_pieceStorage->getDiskAdaptor()->getFilePath().c_str());
}
if(progressInfoFile->exists()) {
progressInfoFile->load();
_pieceStorage->getDiskAdaptor()->openExistingFile();
} else {
File outfile(getFilePath());
if(outfile.exists() && _option->get(PREF_CONTINUE) == V_TRUE) {
if(getTotalLength() < outfile.size()) {
throw DlAbortEx
(StringFormat(EX_FILE_LENGTH_MISMATCH_BETWEEN_LOCAL_AND_REMOTE,
getFilePath().c_str(),
Util::itos(outfile.size()).c_str(),
Util::itos(getTotalLength()).c_str()).str());
}
while(1) {
if(progressInfoFile->exists()) {
progressInfoFile->load();
_pieceStorage->getDiskAdaptor()->openExistingFile();
_pieceStorage->markPiecesDone(outfile.size());
} else {
#ifdef ENABLE_MESSAGE_DIGEST
if(outfile.exists() && _option->get(PREF_CHECK_INTEGRITY) == V_TRUE) {
File outfile(getFilePath());
if(outfile.exists() && _option->get(PREF_CONTINUE) == V_TRUE) {
if(getTotalLength() < outfile.size()) {
throw DlAbortEx
(StringFormat(EX_FILE_LENGTH_MISMATCH_BETWEEN_LOCAL_AND_REMOTE,
getFilePath().c_str(),
Util::itos(outfile.size()).c_str(),
Util::itos(getTotalLength()).c_str()).str());
}
_pieceStorage->getDiskAdaptor()->openExistingFile();
_pieceStorage->markPiecesDone(outfile.size());
} else {
shouldCancelDownloadForSafety();
_pieceStorage->getDiskAdaptor()->initAndOpenFile();
}
#else // ENABLE_MESSAGE_DIGEST
shouldCancelDownloadForSafety();
_pieceStorage->getDiskAdaptor()->initAndOpenFile();
#ifdef ENABLE_MESSAGE_DIGEST
if(outfile.exists() && _option->get(PREF_CHECK_INTEGRITY) == V_TRUE) {
_pieceStorage->getDiskAdaptor()->openExistingFile();
} else {
#endif // ENABLE_MESSAGE_DIGEST
shouldCancelDownloadForSafety();
// call updateFilename here in case when filename is renamed
// by tryAutoFileRenaming()
progressInfoFile->updateFilename();
if(progressInfoFile->exists()) {
continue;
}
_pieceStorage->getDiskAdaptor()->initAndOpenFile();
#ifdef ENABLE_MESSAGE_DIGEST
}
#endif // ENABLE_MESSAGE_DIGEST
}
}
setProgressInfoFile(progressInfoFile);
break;
}
setProgressInfoFile(progressInfoFile);
} catch(RecoverableException& e) {
throw DownloadFailureException
(StringFormat(EX_DOWNLOAD_ABORTED).str(), e);
@ -430,12 +438,20 @@ bool RequestGroup::tryAutoFileRenaming()
if(filepath.empty()) {
return false;
}
SingleFileDownloadContextHandle ctx =
dynamic_pointer_cast<SingleFileDownloadContext>(_downloadContext);
// Make a copy of ctx.
SingleFileDownloadContextHandle tempCtx(new SingleFileDownloadContext(*ctx.get()));
DefaultBtProgressInfoFile tempInfoFile(tempCtx, SharedHandle<PieceStorage>(), 0);
for(unsigned int i = 1; i < 10000; ++i) {
File newfile(filepath+"."+Util::uitos(i));
if(!newfile.exists()) {
SingleFileDownloadContextHandle ctx =
dynamic_pointer_cast<SingleFileDownloadContext>(_downloadContext);
ctx->setUFilename(newfile.getBasename());
std::string newFilename = newfile.getBasename();
tempCtx->setUFilename(newFilename);
tempInfoFile.updateFilename();
if(!newfile.exists() || (newfile.exists() && tempInfoFile.exists())) {
ctx->setUFilename(newFilename);
return true;
}
}

View File

@ -24,6 +24,7 @@ class DefaultBtProgressInfoFileTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testLoad);
CPPUNIT_TEST(testLoad_nonBt);
CPPUNIT_TEST(testLoad_nonBt_pieceLengthShorter);
CPPUNIT_TEST(testUpdateFilename);
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<MockBtContext> _btContext;
@ -77,6 +78,7 @@ public:
void testSave_nonBt();
void testLoad_nonBt();
void testLoad_nonBt_pieceLengthShorter();
void testUpdateFilename();
};
#undef BLOCK_LENGTH
@ -383,4 +385,21 @@ void DefaultBtProgressInfoFileTest::testSave()
}
void DefaultBtProgressInfoFileTest::testUpdateFilename()
{
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(1024, 81920, "file1"));
DefaultBtProgressInfoFile infoFile(dctx, SharedHandle<MockPieceStorage>(), 0);
CPPUNIT_ASSERT_EQUAL(std::string("./file1.aria2"), infoFile.getFilename());
dctx->setUFilename("file1.1");
CPPUNIT_ASSERT_EQUAL(std::string("./file1.aria2"), infoFile.getFilename());
infoFile.updateFilename();
CPPUNIT_ASSERT_EQUAL(std::string("./file1.1.aria2"), infoFile.getFilename());
}
} // namespace aria2

View File

@ -29,6 +29,8 @@ public:
virtual void load() {}
virtual void removeFile() {}
virtual void updateFilename() {}
};
} // namespace aria2