瀏覽代碼

2010-07-16 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	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
Tatsuhiro Tsujikawa 15 年之前
父節點
當前提交
34036e58af
共有 11 個文件被更改,包括 91 次插入1 次删除
  1. 16 0
      ChangeLog
  2. 10 0
      doc/aria2c.1
  3. 13 1
      doc/aria2c.1.html
  4. 8 0
      doc/aria2c.1.txt
  5. 13 0
      src/DefaultPieceStorage.cc
  6. 10 0
      src/OptionHandlerFactory.cc
  7. 2 0
      src/prefs.cc
  8. 2 0
      src/prefs.h
  9. 8 0
      src/usage_text.h
  10. 6 0
      src/util.cc
  11. 3 0
      src/util.h

+ 16 - 0
ChangeLog

@@ -1,3 +1,19 @@
+2010-07-16  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	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  <t-tujikawa@users.sourceforge.net>
 
 	Updated doc of --split option.

+ 10 - 0
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

+ 13 - 1
doc/aria2c.1.html

@@ -2077,6 +2077,18 @@ name.</td>
 </p>
 </dd>
 <dt class="hdlist1">
+<strong>--on-bt-download-complete</strong>=COMMAND
+</dt>
+<dd>
+<p>
+  For BitTorrent, a command specified in <strong>--on-download-complete</strong> 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 <strong>--on-download-start</strong> option for
+  the requirement of COMMAND.  Possible Values: <em>/path/to/command</em>
+</p>
+</dd>
+<dt class="hdlist1">
 <strong>--on-download-complete</strong>=COMMAND
 </dt>
 <dd>
@@ -4230,7 +4242,7 @@ files in the program, then also delete it here.</p></div>
 <div id="footnotes"><hr /></div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2010-07-16 23:25:07 JST
+Last updated 2010-07-16 23:44:34 JST
 </div>
 </div>
 </body>

+ 8 - 0
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

+ 13 - 0
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>& piece)
     } else {
       logger_->info(MSG_DOWNLOAD_COMPLETED);
     }
+#ifdef ENABLE_BITTORRENT
+    if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
+      SharedHandle<TorrentAttribute> torrentAttrs =
+        bittorrent::getTorrentAttrs(downloadContext_);
+      if(!torrentAttrs->metadata.empty()) {
+        util::executeHookByOptName(downloadContext_->getOwnerRequestGroup(),
+                                   option_, PREF_ON_BT_DOWNLOAD_COMPLETE);
+      }
+    }
+#endif // ENABLE_BITTORRENT
   }
 }
 

+ 10 - 0
src/OptionHandlerFactory.cc

@@ -1401,6 +1401,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_BITTORRENT);
     handlers.push_back(op);
   }
+  {
+    SharedHandle<OptionHandler> 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<NumberOptionHandler> op(new NumberOptionHandler
                                          (PREF_PEER_CONNECTION_TIMEOUT,

+ 2 - 0
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

+ 2 - 0
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

+ 8 - 0
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.")

+ 6 - 0
src/util.cc

@@ -1394,6 +1394,12 @@ void executeHook(const std::string& command, gid_t gid)
 void executeHookByOptName
 (const SharedHandle<RequestGroup>& 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());

+ 3 - 0
src/util.h

@@ -402,6 +402,9 @@ void executeHookByOptName
 (const SharedHandle<RequestGroup>& group, const Option* option,
  const std::string& opt);
 
+void executeHookByOptName
+(const RequestGroup* group, const Option* option, const std::string& opt);
+
 } // namespace util
 
 } // namespace aria2