diff --git a/ChangeLog b/ChangeLog index 00f2a6eb..d628d596 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-11-23 Tatsuhiro Tsujikawa + + Throw DlAbortEx when a remote file is not found. + * src/HttpResponse.cc + * src/FtpNegotiationCommand.cc + * src/message.h + + Overwrite an existing file if --allow-overwrite=true is given. + * src/RequestGroup.cc + + Removed unused functions + * src/AbstractCommand.h + 2007-11-23 Tatsuhiro Tsujikawa Removed 'extern' from 'extern typedef ...' in src/*.h diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 34be35b7..cce0b15d 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -78,18 +78,8 @@ protected: #endif // ENABLE_ASYNC_DNS void setTimeout(int32_t timeout) { this->timeout = timeout; } - void loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoFile); - - bool tryAutoFileRenaming(); - - void initPieceStorage(); - - bool downloadFinishedByFileLength(); - void prepareForNextAction(Command* nextCommand = 0); - void shouldCancelDownloadForSafety(); - private: bool checkSocketIsReadable; bool checkSocketIsWritable; diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index c15c6bc3..60759352 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -190,6 +190,14 @@ bool FtpNegotiationCommand::recvSize() { if(status == 0) { return false; } + if(status == 550) { + // If file is not found in a server, then SIZE command fails. + // TODO There exist ftp servers that don't support SIZE command... + // the message "MSG_RESOURCE_NOT_FOUND" may be a little bit confusing. + // Nevertheless, curretly aria2 doesn't support such ftp servers, + // I don't care that. + throw new DlAbortEx(MSG_RESOURCE_NOT_FOUND); + } if(status != 213) { throw new DlRetryEx(EX_BAD_STATUS, status); } diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index df2e042e..a6d5a7d5 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -44,6 +44,9 @@ void HttpResponse::validateResponse() const if(status == 401) { throw new DlAbortEx(EX_AUTH_FAILED); } + if(status == 404) { + throw new DlAbortEx(MSG_RESOURCE_NOT_FOUND); + } if(status >= 400) { throw new DlRetryEx(EX_BAD_STATUS, status); } diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index c8f476f2..5f2e2b7f 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -193,11 +193,9 @@ Commands RequestGroup::createInitialCommand(DownloadEngine* e) if(_pieceStorage->getDiskAdaptor()->fileExists()) { if(_option->get(PREF_CHECK_INTEGRITY) != V_TRUE && _option->get(PREF_ALLOW_OVERWRITE) != V_TRUE) { - _logger->error(MSG_FILE_ALREADY_EXISTS, - getFilePath().c_str(), - progressInfoFile->getFilename().c_str()); // TODO we need this->haltRequested = true? - return Commands(); + throw new DownloadFailureException(MSG_FILE_ALREADY_EXISTS, + getFilePath().c_str()); } else { _pieceStorage->getDiskAdaptor()->openFile(); } @@ -272,7 +270,9 @@ void RequestGroup::initPieceStorage() bool RequestGroup::downloadFinishedByFileLength() { - if(_option->get(PREF_CHECK_INTEGRITY) == V_TRUE && + // assuming that a control file doesn't exist. + if(_option->get(PREF_ALLOW_OVERWRITE) == V_TRUE || + _option->get(PREF_CHECK_INTEGRITY) == V_TRUE && !_downloadContext->getPieceHashes().empty()) { return false; } @@ -328,23 +328,24 @@ void RequestGroup::loadAndOpenFile(const BtProgressInfoFileHandle& progressInfoF } } +// assuming that a control file does not exist void RequestGroup::shouldCancelDownloadForSafety() { + if(_option->get(PREF_ALLOW_OVERWRITE) == V_TRUE) { + return; + } File outfile(getFilePath()); - if(outfile.exists() && !_progressInfoFile->exists()) { + if(outfile.exists()) { if(_option->get(PREF_AUTO_FILE_RENAMING) == V_TRUE) { if(tryAutoFileRenaming()) { - _logger->notice("File already exists. Renamed to %s.", - getFilePath().c_str()); + _logger->notice(MSG_FILE_RENAMED, getFilePath().c_str()); } else { - _logger->notice("File renaming failed: %s", getFilePath().c_str()); - throw new DownloadFailureException(EX_DOWNLOAD_ABORTED); + throw new DownloadFailureException("File renaming failed: %s", + getFilePath().c_str()); } - } else if(_option->get(PREF_ALLOW_OVERWRITE) != V_TRUE) { - _logger->notice(MSG_FILE_ALREADY_EXISTS, - getFilePath().c_str(), - _progressInfoFile->getFilename().c_str()); - throw new DownloadFailureException(EX_DOWNLOAD_ABORTED); + } else { + throw new DownloadFailureException(MSG_FILE_ALREADY_EXISTS, + getFilePath().c_str()); } } } diff --git a/src/message.h b/src/message.h index b8fb0b50..08312a0a 100644 --- a/src/message.h +++ b/src/message.h @@ -98,7 +98,7 @@ #define MSG_LOADING_SEGMENT_FILE _("Loading the segment file %s.") #define MSG_LOADED_SEGMENT_FILE _("The segment file was loaded successfully.") #define MSG_NO_URL_TO_DOWNLOAD _("No URI to download. Download aborted.") -#define MSG_FILE_ALREADY_EXISTS _("File %s exists, but %s does not exist. The download was canceled in order to prevent your file from being truncated to 0. If you are sure to download file all over again, then delete it or add --allow-overwrite=true option and restart aria2.") +#define MSG_FILE_ALREADY_EXISTS _("File %s exists, but a control file(*.aria2) does not exist. Download was canceled in order to prevent your file from being truncated to 0. If you are sure to download the file all over again, then delete it or add --allow-overwrite=true option and restart aria2.") #define MSG_ALLOCATING_FILE _("Allocating file %s, %s bytes") #define MSG_FILE_NOT_FOUND _("File not found") #define MSG_NOT_DIRECTORY _("Not a directory") @@ -128,6 +128,8 @@ #define MSG_VERIFICATION_FAILED _("Checksum error detected. file=%s") #define MSG_INCOMPLETE_RANGE _("Incomplete range specified. %s") #define MSG_STRING_INTEGER_CONVERSION_FAILURE _("Failed to convert string into value: %s") +#define MSG_RESOURCE_NOT_FOUND _("Resource not found") +#define MSG_FILE_RENAMED _("File already exists. Renamed to %s.") #define EX_TIME_OUT _("Timeout.") #define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")