From ecbc05012ce252c03a5685ee4f0fd2b93b1fda25 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 28 Nov 2010 17:29:32 +0900 Subject: [PATCH] Added additional error_code::Values(9 through 14). --- src/AbstractDiskWriter.cc | 5 ++-- src/DefaultBtProgressInfoFile.cc | 5 ++-- src/FtpNegotiationCommand.cc | 5 ++-- src/HttpResponseCommand.cc | 5 ++-- src/RequestGroup.cc | 40 +++++++++++++++++++------------- src/error_code.h | 6 +++++ 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index fa0c82a1..e343857a 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -162,10 +162,11 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t // If errno is ENOSPC(not enough space in device), throw // DownloadFailureException and abort download instantly. if(errNum == ENOSPC) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(EX_FILE_WRITE, filename_.c_str(), - util::safeStrerror(errNum).c_str())); + util::safeStrerror(errNum).c_str()), + error_code::NOT_ENOUGH_DISK_SPACE); } else { throw DL_ABORT_EX (fmt(EX_FILE_WRITE, diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index 87b760de..5677ff26 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -409,10 +409,11 @@ void DefaultBtProgressInfoFile::load() src.setBitfield(savedBitfield, bitfieldLength); if((src.getCompletedLength() || numInFlightPiece) && !option_->getAsBool(PREF_ALLOW_PIECE_LENGTH_CHANGE)) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 ("WARNING: Detected a change in piece length. You can proceed with" " --allow-piece-length-change=true, but you may lose some download" - " progress."); + " progress.", + error_code::PIECE_LENGTH_CHANGED); } BitfieldMan dest(dctx_->getPieceLength(), totalLength); util::convertBitfield(&dest, &src); diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 04e90088..2a18f7ac 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -367,9 +367,10 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) getRequestGroup()->preDownloadProcessing(); if(getDownloadEngine()->getRequestGroupMan()-> isSameFileBeingDownloaded(getRequestGroup())) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(EX_DUPLICATE_FILE_DOWNLOAD, - getRequestGroup()->getFirstFilePath().c_str())); + getRequestGroup()->getFirstFilePath().c_str()), + error_code::DUPLICATE_DOWNLOAD); } if(totalLength == 0) { diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index daea80ba..952ed8c1 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -213,9 +213,10 @@ bool HttpResponseCommand::executeInternal() getRequestGroup()->preDownloadProcessing(); if(getDownloadEngine()->getRequestGroupMan()-> isSameFileBeingDownloaded(getRequestGroup())) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(EX_DUPLICATE_FILE_DOWNLOAD, - getRequestGroup()->getFirstFilePath().c_str())); + getRequestGroup()->getFirstFilePath().c_str()), + error_code::DUPLICATE_DOWNLOAD); } // update last modified time updateLastModifiedTime(httpResponse->getLastModifiedTime()); diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 86a94900..e2e92a68 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -298,18 +298,20 @@ void RequestGroup::createInitialCommand if(btRegistry->getDownloadContext(torrentAttrs->infoHash)) { // TODO If metadataGetMode == false and each FileEntry has // URI, then go without BT. - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt("InfoHash %s is already registered.", - bittorrent::getInfoHashString(downloadContext_).c_str())); + bittorrent::getInfoHashString(downloadContext_).c_str()), + error_code::DUPLICATE_INFO_HASH); } if(metadataGetMode) { // Use UnknownLengthPieceStorage. initPieceStorage(); } else { if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(EX_DUPLICATE_FILE_DOWNLOAD, - downloadContext_->getBasePath().c_str())); + downloadContext_->getBasePath().c_str()), + error_code::DUPLICATE_DOWNLOAD); } initPieceStorage(); if(downloadContext_->getFileEntries().size() > 1) { @@ -413,9 +415,10 @@ void RequestGroup::createInitialCommand !option_->getAsBool(PREF_ALLOW_OVERWRITE) && !option_->getAsBool(PREF_BT_SEED_UNVERIFIED)) { // TODO we need this->haltRequested = true? - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(MSG_FILE_ALREADY_EXISTS, - downloadContext_->getBasePath().c_str())); + downloadContext_->getBasePath().c_str()), + error_code::FILE_ALREADY_EXISTS); } else { pieceStorage_->getDiskAdaptor()->openFile(); } @@ -477,9 +480,10 @@ void RequestGroup::createInitialCommand createNextCommand(commands, e, 1); } else { if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(EX_DUPLICATE_FILE_DOWNLOAD, - downloadContext_->getBasePath().c_str())); + downloadContext_->getBasePath().c_str()), + error_code::DUPLICATE_DOWNLOAD); } SharedHandle progressInfoFile (new DefaultBtProgressInfoFile @@ -503,9 +507,10 @@ void RequestGroup::createInitialCommand // In this context, multiple FileEntry objects are in // DownloadContext. if(e->getRequestGroupMan()->isSameFileBeingDownloaded(this)) { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(EX_DUPLICATE_FILE_DOWNLOAD, - downloadContext_->getBasePath().c_str())); + downloadContext_->getBasePath().c_str()), + error_code::DUPLICATE_DOWNLOAD); } initPieceStorage(); if(downloadContext_->getFileEntries().size() > 1) { @@ -526,9 +531,10 @@ void RequestGroup::createInitialCommand if(!isCheckIntegrityReady() && !option_->getAsBool(PREF_ALLOW_OVERWRITE)) { // TODO we need this->haltRequested = true? - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(MSG_FILE_ALREADY_EXISTS, - downloadContext_->getBasePath().c_str())); + downloadContext_->getBasePath().c_str()), + error_code::FILE_ALREADY_EXISTS); } else { pieceStorage_->getDiskAdaptor()->openFile(); } @@ -763,14 +769,16 @@ void RequestGroup::shouldCancelDownloadForSafety() if(tryAutoFileRenaming()) { A2_LOG_NOTICE(fmt(MSG_FILE_RENAMED, getFirstFilePath().c_str())); } else { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt("File renaming failed: %s", - getFirstFilePath().c_str())); + getFirstFilePath().c_str()), + error_code::FILE_RENAMING_FAILED); } } else { - throw DOWNLOAD_FAILURE_EXCEPTION + throw DOWNLOAD_FAILURE_EXCEPTION2 (fmt(MSG_FILE_ALREADY_EXISTS, - getFirstFilePath().c_str())); + getFirstFilePath().c_str()), + error_code::FILE_ALREADY_EXISTS); } } } diff --git a/src/error_code.h b/src/error_code.h index 0dc1a542..3678c6b6 100644 --- a/src/error_code.h +++ b/src/error_code.h @@ -52,6 +52,12 @@ enum Value { NETWORK_PROBLEM = 6, IN_PROGRESS = 7, CANNOT_RESUME = 8, + NOT_ENOUGH_DISK_SPACE = 9, + PIECE_LENGTH_CHANGED = 10, + DUPLICATE_DOWNLOAD = 11, + DUPLICATE_INFO_HASH = 12, + FILE_ALREADY_EXISTS = 13, + FILE_RENAMING_FAILED = 14 }; } // namespace error_code