Kaynağa Gözat

Added aria2.removeDownloadResult XML-RPC method.

The method signature is aria2.removeDownloadResult(gid).  This method
removes completed/error/removed download denoted by gid from
memory. This method returns "OK" for success.
Tatsuhiro Tsujikawa 14 yıl önce
ebeveyn
işleme
fe40876546

+ 23 - 0
doc/aria2c.1.asciidoc

@@ -2425,6 +2425,29 @@ Description
 This method purges completed/error/removed downloads to free memory.
 This method returns "OK".
 
+[[aria2_xmlrpc_aria2_removeDownloadResult]]
+*aria2.removeDownloadResult* ('gid')
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Description
++++++++++++
+
+This method removes completed/error/removed download denoted by 'gid'
+from memory. This method returns "OK" for success.
+
+Example
++++++++
+
+The following example removes the download result of the download
+whose GID is "1".
+
+--------------------------------------------------------------------
+>>> import xmlrpclib
+>>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc')
+>>> s.aria2.removeDownloadResult('1')
+'OK'
+--------------------------------------------------------------------
+
 [[aria2_xmlrpc_aria2_getVersion]]
 *aria2.getVersion* ()
 ^^^^^^^^^^^^^^^^^^^^^

+ 3 - 0
doc/xmlrpc/aria2rpc

@@ -245,6 +245,7 @@ Usage: #{program_name} addUri URI... [options]
        #{program_name} getUris    GID [options]
        #{program_name} getPeers   GID [options]
        #{program_name} purgeDownloadResult [options]
+       #{program_name} removeDownloadResult GID [options]
        #{program_name} changeOption GID [options]
        #{program_name} changeGlobalOption [options]
        #{program_name} getVersion [options]
@@ -338,6 +339,8 @@ elsif command == "getPeers" then
   result=client.call("aria2."+command, resources[0])
 elsif command == "purgeDownloadResult" then
   result=client.call("aria2."+command)
+elsif command == "removeDownloadResult" then
+  result=client.call("aria2."+command, resources[0])
 elsif command == "changeOption" then
   result=client.call("aria2."+command, resources[0], options)
 elsif command == "changeGlobalOption" then

+ 12 - 0
src/RequestGroupMan.cc

@@ -748,6 +748,18 @@ RequestGroupMan::findDownloadResult(gid_t gid) const
   return SharedHandle<DownloadResult>();
 }
 
+bool RequestGroupMan::removeDownloadResult(gid_t gid)
+{
+  for(std::deque<SharedHandle<DownloadResult> >::iterator i =
+        downloadResults_.begin(), eoi = downloadResults_.end(); i != eoi; ++i) {
+    if((*i)->gid == gid) {
+      downloadResults_.erase(i);
+      return true;
+    }
+  }
+  return false;
+}
+
 void RequestGroupMan::addDownloadResult(const SharedHandle<DownloadResult>& dr)
 {
   if(maxDownloadResult_ == 0) {

+ 4 - 0
src/RequestGroupMan.h

@@ -214,6 +214,10 @@ public:
   // Removes all download results.
   void purgeDownloadResult();
 
+  // Removes download result of given gid. Returns true if download
+  // result was removed. Otherwise returns false.
+  bool removeDownloadResult(gid_t gid);
+
   void addDownloadResult(const SharedHandle<DownloadResult>& downloadResult);
 
   SharedHandle<ServerStat> findServerStat(const std::string& hostname,

+ 2 - 0
src/XmlRpcMethodFactory.cc

@@ -105,6 +105,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
     return SharedHandle<XmlRpcMethod>(new ChangeGlobalOptionXmlRpcMethod());
   } else if(methodName == PurgeDownloadResultXmlRpcMethod::getMethodName()) {
     return SharedHandle<XmlRpcMethod>(new PurgeDownloadResultXmlRpcMethod());
+  } else if(methodName == RemoveDownloadResultXmlRpcMethod::getMethodName()) {
+    return SharedHandle<XmlRpcMethod>(new RemoveDownloadResultXmlRpcMethod());
   } else if(methodName == GetVersionXmlRpcMethod::getMethodName()) {
     return SharedHandle<XmlRpcMethod>(new GetVersionXmlRpcMethod());
   } else if(methodName == GetSessionInfoXmlRpcMethod::getMethodName()) {

+ 12 - 0
src/XmlRpcMethodImpl.cc

@@ -986,6 +986,18 @@ SharedHandle<ValueBase> PurgeDownloadResultXmlRpcMethod::process
   return VLB_OK;
 }
 
+SharedHandle<ValueBase> RemoveDownloadResultXmlRpcMethod::process
+(const XmlRpcRequest& req, DownloadEngine* e)
+{
+  gid_t gid = getRequiredGidParam(req, 0);
+  if(!e->getRequestGroupMan()->removeDownloadResult(gid)) {
+    throw DL_ABORT_EX
+      (fmt("Could not remove download result of GID#%s",
+           util::itos(gid).c_str()));
+  }
+  return VLB_OK;
+}
+
 SharedHandle<ValueBase> ChangeOptionXmlRpcMethod::process
 (const XmlRpcRequest& req, DownloadEngine* e)
 {

+ 12 - 0
src/XmlRpcMethodImpl.h

@@ -216,6 +216,18 @@ public:
   }
 };
 
+class RemoveDownloadResultXmlRpcMethod:public XmlRpcMethod {
+protected:
+  virtual SharedHandle<ValueBase> process
+  (const XmlRpcRequest& req, DownloadEngine* e);
+public:
+  static const std::string& getMethodName()
+  {
+    static std::string methodName = "aria2.removeDownloadResult";
+    return methodName;
+  }
+};
+
 class GetUrisXmlRpcMethod:public XmlRpcMethod {
 protected:
   virtual SharedHandle<ValueBase> process