2009-05-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed broken file renaming feature since r1202.
	* src/FtpNegotiationCommand.cc
	* src/FtpNegotiationCommand.h
	* src/HttpResponseCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
pull/1/head
Tatsuhiro Tsujikawa 2009-05-07 03:49:27 +00:00
parent 4432b68d24
commit 030bc08287
6 changed files with 125 additions and 39 deletions

View File

@ -1,3 +1,12 @@
2009-05-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed broken file renaming feature since r1202.
* src/FtpNegotiationCommand.cc
* src/FtpNegotiationCommand.h
* src/HttpResponseCommand.cc
* src/RequestGroup.cc
* src/RequestGroup.h
2009-05-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed unused debug log

View File

@ -341,16 +341,29 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
} else {
sequence = SEQ_PREPARE_SERVER_SOCKET;
}
_requestGroup->initPieceStorage();
if(dctx->knowsTotalLength() &&
_requestGroup->downloadFinishedByFileLength()) {
if(e->option->getAsBool(PREF_DRY_RUN)) {
_requestGroup->initPieceStorage();
onDryRunFileFound();
return false;
}
if(_requestGroup->downloadFinishedByFileLength()) {
_requestGroup->initPieceStorage();
_requestGroup->getPieceStorage()->markAllPiecesDone();
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
_requestGroup->getGID(),
_requestGroup->getFilePath().c_str());
poolConnection();
return false;
}
_requestGroup->shouldCancelDownloadForSafety();
_requestGroup->initPieceStorage();
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
if(dctx->knowsTotalLength()) {
@ -361,19 +374,28 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
return true;
} else {
_requestGroup->adjustFilename
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(_requestGroup->getDownloadContext(),
SharedHandle<PieceStorage>(),
e->option)));
_requestGroup->initPieceStorage();
if(e->option->getAsBool(PREF_DRY_RUN)) {
_requestGroup->getPieceStorage()->markAllPiecesDone();
poolConnection();
sequence = SEQ_HEAD_OK;
onDryRunFileFound();
return false;
}
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
_requestGroup->getPieceStorage()->markAllPiecesDone();
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
_requestGroup->getGID(),
_requestGroup->getFilePath().c_str());
poolConnection();
return false;
@ -649,4 +671,11 @@ void FtpNegotiationCommand::poolConnection() const
}
}
void FtpNegotiationCommand::onDryRunFileFound()
{
_requestGroup->getPieceStorage()->markAllPiecesDone();
poolConnection();
sequence = SEQ_HEAD_OK;
}
} // namespace aria2

View File

@ -112,6 +112,8 @@ private:
bool onFileSizeDetermined(uint64_t totalLength);
void onDryRunFileFound();
SharedHandle<SocketCore> dataSocket;
SharedHandle<SocketCore> serverSocket;
Seq sequence;

View File

@ -216,6 +216,11 @@ bool HttpResponseCommand::shouldInflateContentEncoding
bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpResponse)
{
HttpRequestHandle httpRequest = httpResponse->getHttpRequest();
_requestGroup->adjustFilename
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(_requestGroup->getDownloadContext(),
SharedHandle<PieceStorage>(),
e->option)));
_requestGroup->initPieceStorage();
if(e->option->getAsBool(PREF_DRY_RUN)) {
@ -225,6 +230,12 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
_requestGroup->getPieceStorage()->markAllPiecesDone();
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
_requestGroup->getGID(),
_requestGroup->getFilePath().c_str());
return true;
}
@ -308,16 +319,23 @@ bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResp
req->setMethod(Request::METHOD_GET);
return prepareForRetry(0);
}
_requestGroup->initPieceStorage();
// For zero-length file, check existing file comparing its size
if(_requestGroup->getDownloadContext()->knowsTotalLength() &&
_requestGroup->downloadFinishedByFileLength()) {
if(_requestGroup->downloadFinishedByFileLength()) {
_requestGroup->initPieceStorage();
_requestGroup->getPieceStorage()->markAllPiecesDone();
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
_requestGroup->getGID(),
_requestGroup->getFilePath().c_str());
poolConnection();
return true;
}
_requestGroup->shouldCancelDownloadForSafety();
_requestGroup->initPieceStorage();
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
// In this context, knowsTotalLength() is true only when the file is

View File

@ -363,10 +363,19 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
getFilePath().c_str()).str());
}
adjustFilename
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(_downloadContext,
SharedHandle<PieceStorage>(),
_option)));
initPieceStorage();
BtProgressInfoFileHandle infoFile
(new DefaultBtProgressInfoFile(_downloadContext, _pieceStorage, _option));
if(infoFile->exists() || !downloadFinishedByFileLength()) {
if(!infoFile->exists() && downloadFinishedByFileLength()) {
_pieceStorage->markAllPiecesDone();
_logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
_gid, getFilePath().c_str());
} else {
loadAndOpenFile(infoFile);
SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
(new StreamCheckIntegrityEntry(SharedHandle<Request>(), this));
@ -436,17 +445,46 @@ bool RequestGroup::downloadFinishedByFileLength()
!_downloadContext->getPieceHashes().empty())) {
return false;
}
if(!_downloadContext->knowsTotalLength()) {
return false;
}
// TODO consider the case when the getFilePath() returns dir path.
File outfile(getFilePath());
if(outfile.exists() && getTotalLength() == outfile.size()) {
_pieceStorage->markAllPiecesDone();
_logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, _gid, getFilePath().c_str());
if(outfile.exists() && _downloadContext->getTotalLength() == outfile.size()) {
return true;
} else {
return false;
}
}
void RequestGroup::adjustFilename
(const SharedHandle<BtProgressInfoFile>& infoFile)
{
if(!isPreLocalFileCheckEnabled()) {
// OK, no need to care about filename.
} else if(infoFile->exists()) {
// Use current filename
} else if(downloadFinishedByFileLength()) {
// File was downloaded already, no need to change file name.
} else {
File outfile(getFilePath());
if(outfile.exists() && _option->getAsBool(PREF_CONTINUE) &&
outfile.size() <= _downloadContext->getTotalLength()) {
// File exists but user decided to resume it.
} else {
#ifdef ENABLE_MESSAGE_DIGEST
if(outfile.exists() && _option->getAsBool(PREF_CHECK_INTEGRITY)) {
// check-integrity existing file
} else {
#endif // ENABLE_MESSAGE_DIGEST
shouldCancelDownloadForSafety();
#ifdef ENABLE_MESSAGE_DIGEST
}
#endif // ENABLE_MESSAGE_DIGEST
}
}
}
void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoFile)
{
try {
@ -461,41 +499,29 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF
progressInfoFile->getFilename().c_str(),
getFilePath().c_str());
}
while(1) {
if(progressInfoFile->exists()) {
progressInfoFile->load();
if(progressInfoFile->exists()) {
progressInfoFile->load();
_pieceStorage->getDiskAdaptor()->openExistingFile();
} else {
File outfile(getFilePath());
if(outfile.exists() && _option->getAsBool(PREF_CONTINUE) &&
outfile.size() <= getTotalLength()) {
_pieceStorage->getDiskAdaptor()->openExistingFile();
_pieceStorage->markPiecesDone(outfile.size());
} else {
File outfile(getFilePath());
if(outfile.exists() && _option->getAsBool(PREF_CONTINUE) &&
outfile.size() <= getTotalLength()) {
#ifdef ENABLE_MESSAGE_DIGEST
if(outfile.exists() && _option->getAsBool(PREF_CHECK_INTEGRITY)) {
_pieceStorage->getDiskAdaptor()->openExistingFile();
_pieceStorage->markPiecesDone(outfile.size());
} else {
#ifdef ENABLE_MESSAGE_DIGEST
if(outfile.exists() && _option->getAsBool(PREF_CHECK_INTEGRITY)) {
_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()) {
// Close DiskAdaptor here. Renmaed file will be opened in the
// next loop .
_pieceStorage->getDiskAdaptor()->closeFile();
continue;
}
_pieceStorage->getDiskAdaptor()->initAndOpenFile();
_pieceStorage->getDiskAdaptor()->initAndOpenFile();
#ifdef ENABLE_MESSAGE_DIGEST
}
#endif // ENABLE_MESSAGE_DIGEST
}
#endif // ENABLE_MESSAGE_DIGEST
}
setProgressInfoFile(progressInfoFile);
break;
}
setProgressInfoFile(progressInfoFile);
} catch(RecoverableException& e) {
throw DownloadFailureException
(StringFormat(EX_DOWNLOAD_ABORTED).str(), e);

View File

@ -371,6 +371,8 @@ public:
void shouldCancelDownloadForSafety();
void adjustFilename(const SharedHandle<BtProgressInfoFile>& infoFile);
SharedHandle<DownloadResult> createDownloadResult() const;
const Option* getOption() const