mirror of https://github.com/aria2/aria2
Make getOption RPC method return option for stopped downloads
parent
fde376efbc
commit
d444a6cc9e
|
@ -1155,13 +1155,18 @@ SharedHandle<ValueBase> GetOptionRpcMethod::process
|
||||||
|
|
||||||
a2_gid_t gid = str2Gid(gidParam);
|
a2_gid_t gid = str2Gid(gidParam);
|
||||||
SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
|
SharedHandle<RequestGroup> group = e->getRequestGroupMan()->findGroup(gid);
|
||||||
if(!group) {
|
|
||||||
throw DL_ABORT_EX(fmt("Cannot get option for GID#%s",
|
|
||||||
GroupId::toHex(gid).c_str()));
|
|
||||||
}
|
|
||||||
SharedHandle<Dict> result = Dict::g();
|
SharedHandle<Dict> result = Dict::g();
|
||||||
SharedHandle<Option> option = group->getOption();
|
if(!group) {
|
||||||
pushRequestOption(result, option, getOptionParser());
|
SharedHandle<DownloadResult> dr =
|
||||||
|
e->getRequestGroupMan()->findDownloadResult(gid);
|
||||||
|
if(!dr) {
|
||||||
|
throw DL_ABORT_EX(fmt("Cannot get option for GID#%s",
|
||||||
|
GroupId::toHex(gid).c_str()));
|
||||||
|
}
|
||||||
|
pushRequestOption(result, dr->option, getOptionParser());
|
||||||
|
} else {
|
||||||
|
pushRequestOption(result, group->getOption(), getOptionParser());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ class RpcMethodTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testAddMetalink_notBase64Metalink);
|
CPPUNIT_TEST(testAddMetalink_notBase64Metalink);
|
||||||
CPPUNIT_TEST(testAddMetalink_withPosition);
|
CPPUNIT_TEST(testAddMetalink_withPosition);
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
|
CPPUNIT_TEST(testGetOption);
|
||||||
CPPUNIT_TEST(testChangeOption);
|
CPPUNIT_TEST(testChangeOption);
|
||||||
CPPUNIT_TEST(testChangeOption_withBadOption);
|
CPPUNIT_TEST(testChangeOption_withBadOption);
|
||||||
CPPUNIT_TEST(testChangeOption_withNotAllowedOption);
|
CPPUNIT_TEST(testChangeOption_withNotAllowedOption);
|
||||||
|
@ -86,6 +87,7 @@ public:
|
||||||
option_.reset(new Option());
|
option_.reset(new Option());
|
||||||
option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_RpcMethodTest");
|
option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_RpcMethodTest");
|
||||||
option_->put(PREF_PIECE_LENGTH, "1048576");
|
option_->put(PREF_PIECE_LENGTH, "1048576");
|
||||||
|
option_->put(PREF_MAX_DOWNLOAD_RESULT, "10");
|
||||||
File(option_->get(PREF_DIR)).mkdirs();
|
File(option_->get(PREF_DIR)).mkdirs();
|
||||||
e_.reset
|
e_.reset
|
||||||
(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
(new DownloadEngine(SharedHandle<EventPoll>(new SelectEventPoll())));
|
||||||
|
@ -114,6 +116,7 @@ public:
|
||||||
void testAddMetalink_notBase64Metalink();
|
void testAddMetalink_notBase64Metalink();
|
||||||
void testAddMetalink_withPosition();
|
void testAddMetalink_withPosition();
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
|
void testGetOption();
|
||||||
void testChangeOption();
|
void testChangeOption();
|
||||||
void testChangeOption_withBadOption();
|
void testChangeOption_withBadOption();
|
||||||
void testChangeOption_withNotAllowedOption();
|
void testChangeOption_withNotAllowedOption();
|
||||||
|
@ -484,6 +487,40 @@ void RpcMethodTest::testAddMetalink_withPosition()
|
||||||
|
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
|
|
||||||
|
void RpcMethodTest::testGetOption()
|
||||||
|
{
|
||||||
|
SharedHandle<RequestGroup> group(new RequestGroup(GroupId::create(),
|
||||||
|
option_));
|
||||||
|
group->getOption()->put(PREF_DIR, "alpha");
|
||||||
|
e_->getRequestGroupMan()->addReservedGroup(group);
|
||||||
|
SharedHandle<DownloadResult> dr = createDownloadResult(error_code::FINISHED,
|
||||||
|
"http://host/fin");
|
||||||
|
dr->option->put(PREF_DIR, "bravo");
|
||||||
|
e_->getRequestGroupMan()->addDownloadResult(dr);
|
||||||
|
|
||||||
|
GetOptionRpcMethod m;
|
||||||
|
RpcRequest req(GetOptionRpcMethod::getMethodName(), List::g());
|
||||||
|
req.params->append(GroupId::toHex(group->getGID()));
|
||||||
|
RpcResponse res = m.execute(req, e_.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
|
const Dict* resopt = downcast<Dict>(res.param);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("alpha"),
|
||||||
|
downcast<String>(resopt->get(PREF_DIR->k))->s());
|
||||||
|
|
||||||
|
req.params = List::g();
|
||||||
|
req.params->append(dr->gid->toHex());
|
||||||
|
res = m.execute(req, e_.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
||||||
|
resopt = downcast<Dict>(res.param);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("bravo"),
|
||||||
|
downcast<String>(resopt->get(PREF_DIR->k))->s());
|
||||||
|
// Invalid GID
|
||||||
|
req.params = List::g();
|
||||||
|
req.params->append(GroupId::create()->toHex());
|
||||||
|
res = m.execute(req, e_.get());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, res.code);
|
||||||
|
}
|
||||||
|
|
||||||
void RpcMethodTest::testChangeOption()
|
void RpcMethodTest::testChangeOption()
|
||||||
{
|
{
|
||||||
SharedHandle<RequestGroup> group(new RequestGroup(GroupId::create(),
|
SharedHandle<RequestGroup> group(new RequestGroup(GroupId::create(),
|
||||||
|
|
Loading…
Reference in New Issue