diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-05-07 03:49:27 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-05-07 03:49:27 +0000 |
| commit | 030bc082872b640765fd092e5cee4920c208a5fd (patch) | |
| tree | 8114aa66550b9fa4579e8e0dfbb4cebc69fd9ba4 /src | |
| parent | 4432b68d24e362618a8b28b73467466e262a1809 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/FtpNegotiationCommand.cc | 41 | ||||
| -rw-r--r-- | src/FtpNegotiationCommand.h | 2 | ||||
| -rw-r--r-- | src/HttpResponseCommand.cc | 24 | ||||
| -rw-r--r-- | src/RequestGroup.cc | 86 | ||||
| -rw-r--r-- | src/RequestGroup.h | 2 |
5 files changed, 116 insertions, 39 deletions
diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index b0bf0fc4..ea9e6314 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -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 diff --git a/src/FtpNegotiationCommand.h b/src/FtpNegotiationCommand.h index 54155ba4..18487033 100644 --- a/src/FtpNegotiationCommand.h +++ b/src/FtpNegotiationCommand.h @@ -112,6 +112,8 @@ private: bool onFileSizeDetermined(uint64_t totalLength); + void onDryRunFileFound(); + SharedHandle<SocketCore> dataSocket; SharedHandle<SocketCore> serverSocket; Seq sequence; diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index 487593e8..d33399a3 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -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 diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index b2bb715d..6bab311d 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -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); diff --git a/src/RequestGroup.h b/src/RequestGroup.h index 94a3e581..e51b224d 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -371,6 +371,8 @@ public: void shouldCancelDownloadForSafety(); + void adjustFilename(const SharedHandle<BtProgressInfoFile>& infoFile); + SharedHandle<DownloadResult> createDownloadResult() const; const Option* getOption() const |
