mirror of https://github.com/aria2/aria2
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.hpull/1/head
parent
4432b68d24
commit
030bc08287
|
@ -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>
|
2009-05-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Removed unused debug log
|
Removed unused debug log
|
||||||
|
|
|
@ -341,16 +341,29 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
} else {
|
} else {
|
||||||
sequence = SEQ_PREPARE_SERVER_SOCKET;
|
sequence = SEQ_PREPARE_SERVER_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(e->option->getAsBool(PREF_DRY_RUN)) {
|
||||||
_requestGroup->initPieceStorage();
|
_requestGroup->initPieceStorage();
|
||||||
if(dctx->knowsTotalLength() &&
|
onDryRunFileFound();
|
||||||
_requestGroup->downloadFinishedByFileLength()) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_requestGroup->downloadFinishedByFileLength()) {
|
||||||
|
_requestGroup->initPieceStorage();
|
||||||
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||||
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
||||||
|
|
||||||
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
|
_requestGroup->getGID(),
|
||||||
|
_requestGroup->getFilePath().c_str());
|
||||||
|
|
||||||
poolConnection();
|
poolConnection();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_requestGroup->shouldCancelDownloadForSafety();
|
_requestGroup->shouldCancelDownloadForSafety();
|
||||||
|
_requestGroup->initPieceStorage();
|
||||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
||||||
|
|
||||||
if(dctx->knowsTotalLength()) {
|
if(dctx->knowsTotalLength()) {
|
||||||
|
@ -361,19 +374,28 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
_requestGroup->adjustFilename
|
||||||
|
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
|
||||||
|
(_requestGroup->getDownloadContext(),
|
||||||
|
SharedHandle<PieceStorage>(),
|
||||||
|
e->option)));
|
||||||
_requestGroup->initPieceStorage();
|
_requestGroup->initPieceStorage();
|
||||||
|
|
||||||
if(e->option->getAsBool(PREF_DRY_RUN)) {
|
if(e->option->getAsBool(PREF_DRY_RUN)) {
|
||||||
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
onDryRunFileFound();
|
||||||
poolConnection();
|
|
||||||
sequence = SEQ_HEAD_OK;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
|
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
|
||||||
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
||||||
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||||
|
|
||||||
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
||||||
|
|
||||||
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
|
_requestGroup->getGID(),
|
||||||
|
_requestGroup->getFilePath().c_str());
|
||||||
|
|
||||||
poolConnection();
|
poolConnection();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -649,4 +671,11 @@ void FtpNegotiationCommand::poolConnection() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FtpNegotiationCommand::onDryRunFileFound()
|
||||||
|
{
|
||||||
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||||
|
poolConnection();
|
||||||
|
sequence = SEQ_HEAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -112,6 +112,8 @@ private:
|
||||||
|
|
||||||
bool onFileSizeDetermined(uint64_t totalLength);
|
bool onFileSizeDetermined(uint64_t totalLength);
|
||||||
|
|
||||||
|
void onDryRunFileFound();
|
||||||
|
|
||||||
SharedHandle<SocketCore> dataSocket;
|
SharedHandle<SocketCore> dataSocket;
|
||||||
SharedHandle<SocketCore> serverSocket;
|
SharedHandle<SocketCore> serverSocket;
|
||||||
Seq sequence;
|
Seq sequence;
|
||||||
|
|
|
@ -216,6 +216,11 @@ bool HttpResponseCommand::shouldInflateContentEncoding
|
||||||
bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpResponse)
|
bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpResponse)
|
||||||
{
|
{
|
||||||
HttpRequestHandle httpRequest = httpResponse->getHttpRequest();
|
HttpRequestHandle httpRequest = httpResponse->getHttpRequest();
|
||||||
|
_requestGroup->adjustFilename
|
||||||
|
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
|
||||||
|
(_requestGroup->getDownloadContext(),
|
||||||
|
SharedHandle<PieceStorage>(),
|
||||||
|
e->option)));
|
||||||
_requestGroup->initPieceStorage();
|
_requestGroup->initPieceStorage();
|
||||||
|
|
||||||
if(e->option->getAsBool(PREF_DRY_RUN)) {
|
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));
|
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
|
||||||
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
||||||
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||||
|
|
||||||
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
|
_requestGroup->getGID(),
|
||||||
|
_requestGroup->getFilePath().c_str());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,16 +319,23 @@ bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResp
|
||||||
req->setMethod(Request::METHOD_GET);
|
req->setMethod(Request::METHOD_GET);
|
||||||
return prepareForRetry(0);
|
return prepareForRetry(0);
|
||||||
}
|
}
|
||||||
_requestGroup->initPieceStorage();
|
|
||||||
|
|
||||||
// For zero-length file, check existing file comparing its size
|
// For zero-length file, check existing file comparing its size
|
||||||
if(_requestGroup->getDownloadContext()->knowsTotalLength() &&
|
if(_requestGroup->downloadFinishedByFileLength()) {
|
||||||
_requestGroup->downloadFinishedByFileLength()) {
|
_requestGroup->initPieceStorage();
|
||||||
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||||
|
|
||||||
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||||
|
_requestGroup->getGID(),
|
||||||
|
_requestGroup->getFilePath().c_str());
|
||||||
|
|
||||||
poolConnection();
|
poolConnection();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_requestGroup->shouldCancelDownloadForSafety();
|
_requestGroup->shouldCancelDownloadForSafety();
|
||||||
|
_requestGroup->initPieceStorage();
|
||||||
|
|
||||||
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
||||||
|
|
||||||
// In this context, knowsTotalLength() is true only when the file is
|
// In this context, knowsTotalLength() is true only when the file is
|
||||||
|
|
|
@ -363,10 +363,19 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
|
||||||
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
||||||
getFilePath().c_str()).str());
|
getFilePath().c_str()).str());
|
||||||
}
|
}
|
||||||
|
adjustFilename
|
||||||
|
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
|
||||||
|
(_downloadContext,
|
||||||
|
SharedHandle<PieceStorage>(),
|
||||||
|
_option)));
|
||||||
initPieceStorage();
|
initPieceStorage();
|
||||||
BtProgressInfoFileHandle infoFile
|
BtProgressInfoFileHandle infoFile
|
||||||
(new DefaultBtProgressInfoFile(_downloadContext, _pieceStorage, _option));
|
(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);
|
loadAndOpenFile(infoFile);
|
||||||
SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
|
SharedHandle<CheckIntegrityEntry> checkIntegrityEntry
|
||||||
(new StreamCheckIntegrityEntry(SharedHandle<Request>(), this));
|
(new StreamCheckIntegrityEntry(SharedHandle<Request>(), this));
|
||||||
|
@ -436,17 +445,46 @@ bool RequestGroup::downloadFinishedByFileLength()
|
||||||
!_downloadContext->getPieceHashes().empty())) {
|
!_downloadContext->getPieceHashes().empty())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(!_downloadContext->knowsTotalLength()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// TODO consider the case when the getFilePath() returns dir path.
|
// TODO consider the case when the getFilePath() returns dir path.
|
||||||
File outfile(getFilePath());
|
File outfile(getFilePath());
|
||||||
if(outfile.exists() && getTotalLength() == outfile.size()) {
|
if(outfile.exists() && _downloadContext->getTotalLength() == outfile.size()) {
|
||||||
_pieceStorage->markAllPiecesDone();
|
|
||||||
_logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, _gid, getFilePath().c_str());
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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)
|
void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoFile)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -461,7 +499,7 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF
|
||||||
progressInfoFile->getFilename().c_str(),
|
progressInfoFile->getFilename().c_str(),
|
||||||
getFilePath().c_str());
|
getFilePath().c_str());
|
||||||
}
|
}
|
||||||
while(1) {
|
|
||||||
if(progressInfoFile->exists()) {
|
if(progressInfoFile->exists()) {
|
||||||
progressInfoFile->load();
|
progressInfoFile->load();
|
||||||
_pieceStorage->getDiskAdaptor()->openExistingFile();
|
_pieceStorage->getDiskAdaptor()->openExistingFile();
|
||||||
|
@ -477,16 +515,6 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF
|
||||||
_pieceStorage->getDiskAdaptor()->openExistingFile();
|
_pieceStorage->getDiskAdaptor()->openExistingFile();
|
||||||
} else {
|
} else {
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#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
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
}
|
}
|
||||||
|
@ -494,8 +522,6 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setProgressInfoFile(progressInfoFile);
|
setProgressInfoFile(progressInfoFile);
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
throw DownloadFailureException
|
throw DownloadFailureException
|
||||||
(StringFormat(EX_DOWNLOAD_ABORTED).str(), e);
|
(StringFormat(EX_DOWNLOAD_ABORTED).str(), e);
|
||||||
|
|
|
@ -371,6 +371,8 @@ public:
|
||||||
|
|
||||||
void shouldCancelDownloadForSafety();
|
void shouldCancelDownloadForSafety();
|
||||||
|
|
||||||
|
void adjustFilename(const SharedHandle<BtProgressInfoFile>& infoFile);
|
||||||
|
|
||||||
SharedHandle<DownloadResult> createDownloadResult() const;
|
SharedHandle<DownloadResult> createDownloadResult() const;
|
||||||
|
|
||||||
const Option* getOption() const
|
const Option* getOption() const
|
||||||
|
|
Loading…
Reference in New Issue