diff --git a/ChangeLog b/ChangeLog index 42fa7bf0..97e04154 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2010-07-16 Tatsuhiro Tsujikawa + + Added --on-bt-download-complete=COMMAND option. For BitTorrent, a + command specified in --on-download-complete is called when + download completes and seeding is over. On the other hand, this + option set the command to be executed when download completes but + before seeding. + * doc/aria2c.1.txt + * src/DefaultPieceStorage.cc + * src/OptionHandlerFactory.cc + * src/prefs.cc + * src/prefs.h + * src/usage_text.h + * src/util.cc + * src/util.h + 2010-07-16 Tatsuhiro Tsujikawa Updated doc of --split option. diff --git a/doc/aria2c.1 b/doc/aria2c.1 index bc2ff052..e7df3964 100644 --- a/doc/aria2c.1 +++ b/doc/aria2c.1 @@ -1249,6 +1249,16 @@ or \fIdebug\fR .RE .PP +\fB\-\-on\-bt\-download\-complete\fR=COMMAND +.RS 4 +For BitTorrent, a command specified in +\fB\-\-on\-download\-complete\fR +is called when download completes and seeding is over\&. On the other hand, this option set the command to be executed when download completes but before seeding\&. See +\fB\-\-on\-download\-start\fR +option for the requirement of COMMAND\&. Possible Values: +\fI/path/to/command\fR +.RE +.PP \fB\-\-on\-download\-complete\fR=COMMAND .RS 4 Set the command to be executed when download completes\&. See diff --git a/doc/aria2c.1.html b/doc/aria2c.1.html index fc87c352..d6bdb414 100644 --- a/doc/aria2c.1.html +++ b/doc/aria2c.1.html @@ -2077,6 +2077,18 @@ name.

+--on-bt-download-complete=COMMAND +
+
+

+ For BitTorrent, a command specified in --on-download-complete is + called when download completes and seeding is over. On the other + hand, this option set the command to be executed when download + completes but before seeding. See --on-download-start option for + the requirement of COMMAND. Possible Values: /path/to/command +

+
+
--on-download-complete=COMMAND
@@ -4230,7 +4242,7 @@ files in the program, then also delete it here.


diff --git a/doc/aria2c.1.txt b/doc/aria2c.1.txt index d7899daf..e6834aba 100644 --- a/doc/aria2c.1.txt +++ b/doc/aria2c.1.txt @@ -851,6 +851,14 @@ name. LEVEL is either 'debug', 'info', 'notice', 'warn' or 'error'. Default: 'debug' +*--on-bt-download-complete*=COMMAND:: + + For BitTorrent, a command specified in *--on-download-complete* is + called when download completes and seeding is over. On the other + hand, this option set the command to be executed when download + completes but before seeding. See *--on-download-start* option for + the requirement of COMMAND. Possible Values: '/path/to/command' + *--on-download-complete*=COMMAND:: Set the command to be executed when download completes. See diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index a0b0d415..29aa36d6 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -59,6 +59,9 @@ #include "array_fun.h" #include "PieceStatMan.h" #include "wallclock.h" +#ifdef ENABLE_BITTORRENT +# include "bittorrent_helper.h" +#endif // ENABLE_BITTORRENT namespace aria2 { @@ -363,6 +366,16 @@ void DefaultPieceStorage::completePiece(const SharedHandle& piece) } else { logger_->info(MSG_DOWNLOAD_COMPLETED); } +#ifdef ENABLE_BITTORRENT + if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) { + SharedHandle torrentAttrs = + bittorrent::getTorrentAttrs(downloadContext_); + if(!torrentAttrs->metadata.empty()) { + util::executeHookByOptName(downloadContext_->getOwnerRequestGroup(), + option_, PREF_ON_BT_DOWNLOAD_COMPLETE); + } + } +#endif // ENABLE_BITTORRENT } } diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index a0f8d00a..22da4b6b 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -1401,6 +1401,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_BITTORRENT); handlers.push_back(op); } + { + SharedHandle op(new DefaultOptionHandler + (PREF_ON_BT_DOWNLOAD_COMPLETE, + TEXT_ON_BT_DOWNLOAD_COMPLETE, + NO_DEFAULT_VALUE, + "/path/to/command")); + op->addTag(TAG_ADVANCED); + op->addTag(TAG_HOOK); + handlers.push_back(op); + } { SharedHandle op(new NumberOptionHandler (PREF_PEER_CONNECTION_TIMEOUT, diff --git a/src/prefs.cc b/src/prefs.cc index 44655a74..eee818e2 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -354,6 +354,8 @@ const std::string PREF_BT_TRACKER_TIMEOUT("bt-tracker-timeout"); const std::string PREF_BT_TRACKER_CONNECT_TIMEOUT("bt-tracker-connect-timeout"); // values: 1*digit const std::string PREF_DHT_MESSAGE_TIMEOUT("dht-message-timeout"); +// values: string +const std::string PREF_ON_BT_DOWNLOAD_COMPLETE("on-bt-download-complete"); /** * Metalink related preferences diff --git a/src/prefs.h b/src/prefs.h index 273bb861..5beb93f7 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -358,6 +358,8 @@ extern const std::string PREF_BT_TRACKER_TIMEOUT; extern const std::string PREF_BT_TRACKER_CONNECT_TIMEOUT; // values: 1*digit extern const std::string PREF_DHT_MESSAGE_TIMEOUT; +// values: string +extern const std::string PREF_ON_BT_DOWNLOAD_COMPLETE; /** * Metalink related preferences diff --git a/src/usage_text.h b/src/usage_text.h index bd34b847..4e017f8e 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -698,3 +698,11 @@ _(" --conditional-get[=true|false] Download file only when the local file is older\n" \ " than remote file. Currently, this function has\n" \ " many limitations. See man page for details.") +#define TEXT_ON_BT_DOWNLOAD_COMPLETE \ + _(" --on-bt-download-complete=COMMAND For BitTorrent, a command specified in\n" \ + " --on-download-complete is called when download\n" \ + " completes and seeding is over. On the other hand,\n" \ + " this option sets the command to be executed when\n" \ + " download completes but before seeding.\n" \ + " See --on-download-start option for the\n" \ + " requirement of COMMAND.") diff --git a/src/util.cc b/src/util.cc index ea708f31..9c12c6a3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1394,6 +1394,12 @@ void executeHook(const std::string& command, gid_t gid) void executeHookByOptName (const SharedHandle& group, const Option* option, const std::string& opt) +{ + executeHookByOptName(group.get(), option, opt); +} + +void executeHookByOptName +(const RequestGroup* group, const Option* option, const std::string& opt) { if(!option->blank(opt)) { executeHook(option->get(opt), group->getGID()); diff --git a/src/util.h b/src/util.h index 4767d0c7..1cbfa546 100644 --- a/src/util.h +++ b/src/util.h @@ -402,6 +402,9 @@ void executeHookByOptName (const SharedHandle& group, const Option* option, const std::string& opt); +void executeHookByOptName +(const RequestGroup* group, const Option* option, const std::string& opt); + } // namespace util } // namespace aria2