diff --git a/ChangeLog b/ChangeLog index 5f4b1ab7..b3d7cb8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2009-03-08 Tatsuhiro Tsujikawa + + Added --dry-run option. In this mode, aria2 just checks whether + the remote file is available and doesn't download data. This + option has effect on HTTP/FTP downloads and BitTorrent downloads + are canceled in this mode. + * src/FtpNegotiationCommand.cc + * src/HttpResponseCommand.cc + * src/HttpResponseCommand.h + * src/OptionHandlerFactory.cc + * src/RequestGroup.cc + * src/RequestGroupMan.cc + * src/prefs.cc + * src/prefs.h + * src/usage_text.h + 2009-03-08 Tatsuhiro Tsujikawa Fixed compiler waring diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 35fdbe42..3c2a3276 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -363,6 +363,13 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) } else { _requestGroup->initPieceStorage(); + if(e->option->getAsBool(PREF_DRY_RUN)) { + _requestGroup->getPieceStorage()->markAllPiecesDone(); + poolConnection(); + sequence = SEQ_HEAD_OK; + return false; + } + BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option)); if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) { sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED; diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index c40e0049..1f00d72d 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -197,6 +197,11 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe HttpRequestHandle httpRequest = httpResponse->getHttpRequest(); _requestGroup->initPieceStorage(); + if(e->option->getAsBool(PREF_DRY_RUN)) { + onDryRunFileFound(); + return true; + } + BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option)); if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) { return true; @@ -270,6 +275,13 @@ static SharedHandle getContentEncodingDecoder bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResponse) { // We assume that RequestGroup::getTotalLength() == 0 here HttpRequestHandle httpRequest = httpResponse->getHttpRequest(); + + if(e->option->getAsBool(PREF_DRY_RUN)) { + _requestGroup->initPieceStorage(); + onDryRunFileFound(); + return true; + } + if(req->getMethod() == Request::METHOD_HEAD) { poolConnection(); req->setMethod(Request::METHOD_GET); @@ -359,4 +371,10 @@ void HttpResponseCommand::poolConnection() } } +void HttpResponseCommand::onDryRunFileFound() +{ + _requestGroup->getPieceStorage()->markAllPiecesDone(); + poolConnection(); +} + } // namespace aria2 diff --git a/src/HttpResponseCommand.h b/src/HttpResponseCommand.h index f439b19f..be773d2b 100644 --- a/src/HttpResponseCommand.h +++ b/src/HttpResponseCommand.h @@ -64,6 +64,8 @@ private: void updateLastModifiedTime(const Time& lastModified); void poolConnection(); + + void onDryRunFileFound(); protected: bool executeInternal(); diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index d00cb667..72802cd2 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -369,6 +369,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_HTTP); handlers.push_back(op); } + { + SharedHandle op(new BooleanOptionHandler + (PREF_DRY_RUN, + TEXT_DRY_RUN, + V_FALSE, + OptionHandler::OPT_ARG)); + op->addTag(TAG_FTP); + op->addTag(TAG_HTTP); + handlers.push_back(op); + } { SharedHandle op(new UnitNumberOptionHandler (PREF_LOWEST_SPEED_LIMIT, diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index ceb042d5..adc50835 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -144,9 +144,10 @@ RequestGroup::RequestGroup(const Option* option, // and add this list. // ACCEPT_METALINK is used for `transparent metalink'. addAcceptType(ACCEPT_METALINK); - - initializePreDownloadHandler(); - initializePostDownloadHandler(); + if(!_option->getAsBool(PREF_DRY_RUN)) { + initializePreDownloadHandler(); + initializePostDownloadHandler(); + } } RequestGroup::~RequestGroup() {} @@ -204,6 +205,11 @@ void RequestGroup::createInitialCommand(std::deque& commands, { BtContextHandle btContext = dynamic_pointer_cast(_downloadContext); if(!btContext.isNull()) { + if(_option->getAsBool(PREF_DRY_RUN)) { + throw DownloadFailureException + ("Cancel BitTorrent download in dry-run context."); + } + if(e->_requestGroupMan->isSameFileBeingDownloaded(this)) { throw DownloadFailureException (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD, @@ -328,7 +334,8 @@ void RequestGroup::createInitialCommand(std::deque& commands, #endif // ENABLE_BITTORRENT // TODO I assume here when totallength is set to DownloadContext and it is // not 0, then filepath is also set DownloadContext correctly.... - if(_downloadContext->getTotalLength() == 0) { + if(_option->getAsBool(PREF_DRY_RUN) || + _downloadContext->getTotalLength() == 0) { createNextCommand(commands, e, 1, method); }else { if(e->_requestGroupMan->isSameFileBeingDownloaded(this)) { diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 0541be34..8ea90783 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -317,7 +317,8 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e) configureRequestGroup(groupToAdd); Commands commands; createInitialCommand(groupToAdd, commands, e, - _option->getAsBool(PREF_USE_HEAD)); + _option->getAsBool(PREF_USE_HEAD)|| + _option->getAsBool(PREF_DRY_RUN)); _requestGroups.push_back(groupToAdd); ++count; e->addCommand(commands); diff --git a/src/prefs.cc b/src/prefs.cc index 7cc23d64..44f5a323 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -158,6 +158,8 @@ const std::string PREF_HTTP_SERVER_LISTEN_PORT("http-server-listen-port"); const std::string PREF_ENABLE_HTTP_SERVER("enable-http-server"); // value: true | false const std::string PREF_RESET_URI("reset-uri"); +// value: true | false +const std::string PREF_DRY_RUN("dry-run"); /** * FTP related preferences diff --git a/src/prefs.h b/src/prefs.h index 1cc1cca2..6230f88c 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -162,6 +162,8 @@ extern const std::string PREF_HTTP_SERVER_LISTEN_PORT; extern const std::string PREF_ENABLE_HTTP_SERVER; // value: true | false extern const std::string PREF_RESET_URI; +// value: true | false +extern const std::string PREF_DRY_RUN; /** * FTP related preferences diff --git a/src/usage_text.h b/src/usage_text.h index ffce426c..76cb875f 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -499,3 +499,9 @@ _(" -O, --index-out=INDEX=PATH Set file path for file with index=INDEX. You ca " PATH is a relative path to the path specified in\n"\ " --dir option. You can use this option multiple\n"\ " times.") +#define TEXT_DRY_RUN \ +_(" --dry-run[=true|false] If true is given, aria2 just checks whether the\n"\ + " remote file is available and doesn't download\n"\ + " data. This option has effect on HTTP/FTP downloads\n"\ + " and BitTorrent downloads are canceled if true is\n"\ + " specified.")