mirror of https://github.com/aria2/aria2
Added --rpc-save-upload-metadata option
If true is given, which is default, save the uploaded torrent or metalink metadata in the directory specified by --dir option. The filename consists of SHA1-hash hex string of metadata plus extension. For torrent, the extension is '.torrent'. For metalink, it is '.meta4'. If false is given to this option, the downloads added by aria2.addTorrent or aria2.addMetalink will not be saved by --save-session option.pull/28/head
parent
4a4fec2c8c
commit
a9c76ed35e
|
@ -792,6 +792,17 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
||||||
op->addTag(TAG_RPC);
|
op->addTag(TAG_RPC);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
OptionHandler* op(new BooleanOptionHandler
|
||||||
|
(PREF_RPC_SAVE_UPLOAD_METADATA,
|
||||||
|
TEXT_RPC_SAVE_UPLOAD_METADATA,
|
||||||
|
A2_V_TRUE,
|
||||||
|
OptionHandler::OPT_ARG));
|
||||||
|
op->addTag(TAG_RPC);
|
||||||
|
op->setInitialOption(true);
|
||||||
|
op->setChangeGlobalOption(true);
|
||||||
|
handlers.push_back(op);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
OptionHandler* op(new BooleanOptionHandler
|
OptionHandler* op(new BooleanOptionHandler
|
||||||
(PREF_RPC_SECURE,
|
(PREF_RPC_SECURE,
|
||||||
|
|
|
@ -278,19 +278,23 @@ SharedHandle<ValueBase> AddTorrentRpcMethod::process
|
||||||
bool posGiven = checkPosParam(posParam);
|
bool posGiven = checkPosParam(posParam);
|
||||||
size_t pos = posGiven ? posParam->i() : 0;
|
size_t pos = posGiven ? posParam->i() : 0;
|
||||||
|
|
||||||
std::string filename = util::applyDir
|
std::string filename;
|
||||||
(requestOption->get(PREF_DIR), getHexSha1(torrentParam->s())+".torrent");
|
if(requestOption->getAsBool(PREF_RPC_SAVE_UPLOAD_METADATA)) {
|
||||||
std::vector<SharedHandle<RequestGroup> > result;
|
filename = util::applyDir
|
||||||
// Save uploaded data in order to save this download in
|
(requestOption->get(PREF_DIR), getHexSha1(torrentParam->s())+".torrent");
|
||||||
// --save-session file.
|
// Save uploaded data in order to save this download in
|
||||||
if(util::saveAs(filename, torrentParam->s(), true)) {
|
// --save-session file.
|
||||||
A2_LOG_INFO(fmt("Uploaded torrent data was saved as %s", filename.c_str()));
|
if(util::saveAs(filename, torrentParam->s(), true)) {
|
||||||
requestOption->put(PREF_TORRENT_FILE, filename);
|
A2_LOG_INFO(fmt("Uploaded torrent data was saved as %s",
|
||||||
} else {
|
filename.c_str()));
|
||||||
A2_LOG_INFO(fmt("Uploaded torrent data was not saved."
|
requestOption->put(PREF_TORRENT_FILE, filename);
|
||||||
" Failed to write file %s", filename.c_str()));
|
} else {
|
||||||
filename.clear();
|
A2_LOG_INFO(fmt("Uploaded torrent data was not saved."
|
||||||
|
" Failed to write file %s", filename.c_str()));
|
||||||
|
filename.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
std::vector<SharedHandle<RequestGroup> > result;
|
||||||
createRequestGroupForBitTorrent(result, requestOption, uris, filename,
|
createRequestGroupForBitTorrent(result, requestOption, uris, filename,
|
||||||
torrentParam->s());
|
torrentParam->s());
|
||||||
|
|
||||||
|
@ -325,22 +329,27 @@ SharedHandle<ValueBase> AddMetalinkRpcMethod::process
|
||||||
|
|
||||||
std::vector<SharedHandle<RequestGroup> > result;
|
std::vector<SharedHandle<RequestGroup> > result;
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
// TODO RFC5854 Metalink has the extension .meta4 and Metalink
|
std::string filename;
|
||||||
// Version 3 uses .metalink extension. We use .meta4 for both
|
if(requestOption->getAsBool(PREF_RPC_SAVE_UPLOAD_METADATA)) {
|
||||||
// RFC5854 Metalink and Version 3. aria2 can detect which of which
|
// TODO RFC5854 Metalink has the extension .meta4 and Metalink
|
||||||
// by reading content rather than extension.
|
// Version 3 uses .metalink extension. We use .meta4 for both
|
||||||
std::string filename = util::applyDir
|
// RFC5854 Metalink and Version 3. aria2 can detect which of which
|
||||||
(requestOption->get(PREF_DIR), getHexSha1(metalinkParam->s())+".meta4");
|
// by reading content rather than extension.
|
||||||
// Save uploaded data in order to save this download in
|
filename = util::applyDir
|
||||||
// --save-session file.
|
(requestOption->get(PREF_DIR), getHexSha1(metalinkParam->s())+".meta4");
|
||||||
if(util::saveAs(filename, metalinkParam->s(), true)) {
|
// Save uploaded data in order to save this download in
|
||||||
A2_LOG_INFO(fmt("Uploaded metalink data was saved as %s",
|
// --save-session file.
|
||||||
filename.c_str()));
|
if(util::saveAs(filename, metalinkParam->s(), true)) {
|
||||||
requestOption->put(PREF_METALINK_FILE, filename);
|
A2_LOG_INFO(fmt("Uploaded metalink data was saved as %s",
|
||||||
createRequestGroupForMetalink(result, requestOption);
|
filename.c_str()));
|
||||||
|
requestOption->put(PREF_METALINK_FILE, filename);
|
||||||
|
createRequestGroupForMetalink(result, requestOption);
|
||||||
|
} else {
|
||||||
|
A2_LOG_INFO(fmt("Uploaded metalink data was not saved."
|
||||||
|
" Failed to write file %s", filename.c_str()));
|
||||||
|
createRequestGroupForMetalink(result, requestOption, metalinkParam->s());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
A2_LOG_INFO(fmt("Uploaded metalink data was not saved."
|
|
||||||
" Failed to write file %s", filename.c_str()));
|
|
||||||
createRequestGroupForMetalink(result, requestOption, metalinkParam->s());
|
createRequestGroupForMetalink(result, requestOption, metalinkParam->s());
|
||||||
}
|
}
|
||||||
#else // !ENABLE_MESSAGE_DIGEST
|
#else // !ENABLE_MESSAGE_DIGEST
|
||||||
|
|
|
@ -277,6 +277,8 @@ const Pref* PREF_RPC_PRIVATE_KEY = makePref("rpc-private-key");
|
||||||
// value: true | false
|
// value: true | false
|
||||||
const Pref* PREF_RPC_SECURE = makePref("rpc-secure");
|
const Pref* PREF_RPC_SECURE = makePref("rpc-secure");
|
||||||
// value: true | false
|
// value: true | false
|
||||||
|
const Pref* PREF_RPC_SAVE_UPLOAD_METADATA = makePref("rpc-save-upload-metadata");
|
||||||
|
// value: true | false
|
||||||
const Pref* PREF_DRY_RUN = makePref("dry-run");
|
const Pref* PREF_DRY_RUN = makePref("dry-run");
|
||||||
// value: true | false
|
// value: true | false
|
||||||
const Pref* PREF_REUSE_URI = makePref("reuse-uri");
|
const Pref* PREF_REUSE_URI = makePref("reuse-uri");
|
||||||
|
|
|
@ -220,6 +220,8 @@ extern const Pref* PREF_RPC_PRIVATE_KEY;
|
||||||
// value: true | false
|
// value: true | false
|
||||||
extern const Pref* PREF_RPC_SECURE;
|
extern const Pref* PREF_RPC_SECURE;
|
||||||
// value: true | false
|
// value: true | false
|
||||||
|
extern const Pref* PREF_RPC_SAVE_UPLOAD_METADATA;
|
||||||
|
// value: true | false
|
||||||
extern const Pref* PREF_DRY_RUN;
|
extern const Pref* PREF_DRY_RUN;
|
||||||
// value: true | false
|
// value: true | false
|
||||||
extern const Pref* PREF_REUSE_URI;
|
extern const Pref* PREF_REUSE_URI;
|
||||||
|
|
|
@ -898,3 +898,14 @@
|
||||||
" scheme. Use --rpc-certificate and\n" \
|
" scheme. Use --rpc-certificate and\n" \
|
||||||
" --rpc-private-key options to specify the\n" \
|
" --rpc-private-key options to specify the\n" \
|
||||||
" server certificate and private key.")
|
" server certificate and private key.")
|
||||||
|
#define TEXT_RPC_SAVE_UPLOAD_METADATA \
|
||||||
|
_(" --rpc-save-upload-metadata[=true|false] Save the uploaded torrent or\n" \
|
||||||
|
" metalink metadata in the directory specified\n" \
|
||||||
|
" by --dir option. The filename consists of\n" \
|
||||||
|
" SHA1-hash hex string of metadata plus\n" \
|
||||||
|
" extension. For torrent, the extension is\n" \
|
||||||
|
" '.torrent'. For metalink, it is '.meta4'.\n" \
|
||||||
|
" If false is given to this option, the\n" \
|
||||||
|
" downloads added by aria2.addTorrent or\n" \
|
||||||
|
" aria2.addMetalink will not be saved by\n" \
|
||||||
|
" --save-session option.")
|
||||||
|
|
|
@ -264,13 +264,23 @@ void RpcMethodTest::testAddTorrent()
|
||||||
SharedHandle<List> uris = List::g();
|
SharedHandle<List> uris = List::g();
|
||||||
uris->append("http://localhost/aria2-0.8.2.tar.bz2");
|
uris->append("http://localhost/aria2-0.8.2.tar.bz2");
|
||||||
req.params->append(uris);
|
req.params->append(uris);
|
||||||
|
{
|
||||||
|
// Saving upload metadata is disabled by option.
|
||||||
|
RpcResponse res = m.execute(req, e_.get());
|
||||||
|
CPPUNIT_ASSERT
|
||||||
|
(!File(e_->getOption()->get(PREF_DIR)+
|
||||||
|
"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("1"), downcast<String>(res.param)->s());
|
||||||
|
}
|
||||||
|
e_->getOption()->put(PREF_RPC_SAVE_UPLOAD_METADATA, A2_V_TRUE);
|
||||||
{
|
{
|
||||||
RpcResponse res = m.execute(req, e_.get());
|
RpcResponse res = m.execute(req, e_.get());
|
||||||
CPPUNIT_ASSERT
|
CPPUNIT_ASSERT
|
||||||
(File(e_->getOption()->get(PREF_DIR)+
|
(File(e_->getOption()->get(PREF_DIR)+
|
||||||
"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
|
"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
|
||||||
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("1"), downcast<String>(res.param)->s());
|
CPPUNIT_ASSERT_EQUAL(std::string("2"), downcast<String>(res.param)->s());
|
||||||
|
|
||||||
SharedHandle<RequestGroup> group =
|
SharedHandle<RequestGroup> group =
|
||||||
e_->getRequestGroupMan()->findReservedGroup(1);
|
e_->getRequestGroupMan()->findReservedGroup(1);
|
||||||
|
@ -296,7 +306,7 @@ void RpcMethodTest::testAddTorrent()
|
||||||
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT_EQUAL
|
||||||
(dir+"/aria2-0.8.2.tar.bz2",
|
(dir+"/aria2-0.8.2.tar.bz2",
|
||||||
e_->getRequestGroupMan()->findReservedGroup(2)->getFirstFilePath());
|
e_->getRequestGroupMan()->findReservedGroup(3)->getFirstFilePath());
|
||||||
CPPUNIT_ASSERT
|
CPPUNIT_ASSERT
|
||||||
(File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
|
(File(dir+"/0a3893293e27ac0490424c06de4d09242215f0a6.torrent").exists());
|
||||||
}
|
}
|
||||||
|
@ -352,12 +362,25 @@ void RpcMethodTest::testAddMetalink()
|
||||||
RpcRequest req(AddMetalinkRpcMethod::getMethodName(), List::g());
|
RpcRequest req(AddMetalinkRpcMethod::getMethodName(), List::g());
|
||||||
req.params->append(readFile(A2_TEST_DIR"/2files.metalink"));
|
req.params->append(readFile(A2_TEST_DIR"/2files.metalink"));
|
||||||
{
|
{
|
||||||
|
// Saving upload metadata is disabled by option.
|
||||||
RpcResponse res = m.execute(req, e_.get());
|
RpcResponse res = m.execute(req, e_.get());
|
||||||
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
const List* resParams = downcast<List>(res.param);
|
const List* resParams = downcast<List>(res.param);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("1"), downcast<String>(resParams->get(0))->s());
|
CPPUNIT_ASSERT_EQUAL(std::string("1"), downcast<String>(resParams->get(0))->s());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("2"), downcast<String>(resParams->get(1))->s());
|
CPPUNIT_ASSERT_EQUAL(std::string("2"), downcast<String>(resParams->get(1))->s());
|
||||||
|
CPPUNIT_ASSERT
|
||||||
|
(!File(e_->getOption()->get(PREF_DIR)+
|
||||||
|
"/c908634fbc257fd56f0114912c2772aeeb4064f4.meta4").exists());
|
||||||
|
}
|
||||||
|
e_->getOption()->put(PREF_RPC_SAVE_UPLOAD_METADATA, A2_V_TRUE);
|
||||||
|
{
|
||||||
|
RpcResponse res = m.execute(req, e_.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
|
const List* resParams = downcast<List>(res.param);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)2, resParams->size());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("3"), downcast<String>(resParams->get(0))->s());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("4"), downcast<String>(resParams->get(1))->s());
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
CPPUNIT_ASSERT
|
CPPUNIT_ASSERT
|
||||||
(File(e_->getOption()->get(PREF_DIR)+
|
(File(e_->getOption()->get(PREF_DIR)+
|
||||||
|
@ -386,7 +409,7 @@ void RpcMethodTest::testAddMetalink()
|
||||||
RpcResponse res = m.execute(req, e_.get());
|
RpcResponse res = m.execute(req, e_.get());
|
||||||
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
CPPUNIT_ASSERT_EQUAL(dir+"/aria2-5.0.0.tar.bz2",
|
CPPUNIT_ASSERT_EQUAL(dir+"/aria2-5.0.0.tar.bz2",
|
||||||
e_->getRequestGroupMan()->findReservedGroup(3)->
|
e_->getRequestGroupMan()->findReservedGroup(5)->
|
||||||
getFirstFilePath());
|
getFirstFilePath());
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
CPPUNIT_ASSERT
|
CPPUNIT_ASSERT
|
||||||
|
|
Loading…
Reference in New Issue