mirror of https://github.com/aria2/aria2
Specify torrent file explicitly in createRequestGroupForBitTorrent()
parent
01e1fdaf49
commit
c1ddf34e4b
|
@ -293,13 +293,13 @@ SharedHandle<ValueBase> AddTorrentRpcMethod::process
|
||||||
if(util::saveAs(filename, torrentParam->s(), true)) {
|
if(util::saveAs(filename, torrentParam->s(), true)) {
|
||||||
A2_LOG_INFO(fmt("Uploaded torrent data was saved as %s", filename.c_str()));
|
A2_LOG_INFO(fmt("Uploaded torrent data was saved as %s", filename.c_str()));
|
||||||
requestOption->put(PREF_TORRENT_FILE, filename);
|
requestOption->put(PREF_TORRENT_FILE, filename);
|
||||||
createRequestGroupForBitTorrent(result, requestOption, uris);
|
|
||||||
} else {
|
} else {
|
||||||
A2_LOG_INFO(fmt("Uploaded torrent data was not saved."
|
A2_LOG_INFO(fmt("Uploaded torrent data was not saved."
|
||||||
" Failed to write file %s", filename.c_str()));
|
" Failed to write file %s", filename.c_str()));
|
||||||
createRequestGroupForBitTorrent(result, requestOption,
|
filename.clear();
|
||||||
uris, torrentParam->s());
|
|
||||||
}
|
}
|
||||||
|
createRequestGroupForBitTorrent(result, requestOption, uris, filename,
|
||||||
|
torrentParam->s());
|
||||||
|
|
||||||
if(!result.empty()) {
|
if(!result.empty()) {
|
||||||
return addRequestGroup(result.front(), e, posGiven, pos);
|
return addRequestGroup(result.front(), e, posGiven, pos);
|
||||||
|
|
|
@ -97,7 +97,8 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
|
||||||
// Don't adjust announce URI because it has been done when
|
// Don't adjust announce URI because it has been done when
|
||||||
// RequestGroup is created with magnet URI.
|
// RequestGroup is created with magnet URI.
|
||||||
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
||||||
std::vector<std::string>(), torrent, false);
|
std::vector<std::string>(),
|
||||||
|
A2STR::NIL, torrent, false);
|
||||||
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
||||||
if(requestGroup->getMetadataInfo()) {
|
if(requestGroup->getMetadataInfo()) {
|
||||||
setMetadataInfo(newRgs.begin(), newRgs.end(),
|
setMetadataInfo(newRgs.begin(), newRgs.end(),
|
||||||
|
|
|
@ -242,13 +242,14 @@ void createRequestGroupForBitTorrent
|
||||||
(std::vector<SharedHandle<RequestGroup> >& result,
|
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||||
const SharedHandle<Option>& option,
|
const SharedHandle<Option>& option,
|
||||||
const std::vector<std::string>& uris,
|
const std::vector<std::string>& uris,
|
||||||
|
const std::string& metaInfoUri,
|
||||||
const std::string& torrentData,
|
const std::string& torrentData,
|
||||||
bool adjustAnnounceUri)
|
bool adjustAnnounceUri)
|
||||||
{
|
{
|
||||||
SharedHandle<ValueBase> torrent;
|
SharedHandle<ValueBase> torrent;
|
||||||
bittorrent::ValueBaseBencodeParser parser;
|
bittorrent::ValueBaseBencodeParser parser;
|
||||||
if(torrentData.empty()) {
|
if(torrentData.empty()) {
|
||||||
torrent = parseFile(parser, option->get(PREF_TORRENT_FILE));
|
torrent = parseFile(parser, metaInfoUri);
|
||||||
} else {
|
} else {
|
||||||
ssize_t error;
|
ssize_t error;
|
||||||
torrent = parser.parseFinal(torrentData.c_str(), torrentData.size(),
|
torrent = parser.parseFinal(torrentData.c_str(), torrentData.size(),
|
||||||
|
@ -258,10 +259,7 @@ void createRequestGroupForBitTorrent
|
||||||
throw DL_ABORT_EX2("Bencode decoding failed",
|
throw DL_ABORT_EX2("Bencode decoding failed",
|
||||||
error_code::BENCODE_PARSE_ERROR);
|
error_code::BENCODE_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
createRequestGroupForBitTorrent(result, option, uris,
|
createRequestGroupForBitTorrent(result, option, uris, metaInfoUri, torrent);
|
||||||
torrentData.empty() ?
|
|
||||||
option->get(PREF_TORRENT_FILE) : "",
|
|
||||||
torrent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void createRequestGroupForBitTorrent
|
void createRequestGroupForBitTorrent
|
||||||
|
|
|
@ -54,18 +54,23 @@ class ValueBase;
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
// Create RequestGroup object using torrent file specified by
|
// Create RequestGroup object using torrent file specified by
|
||||||
// torrent-file option. If non-empty torrentData is specified, then
|
// metaInfoUri, which is treated as local file path. If non-empty
|
||||||
// it is used as a content of torrent file instead. If
|
// torrentData is specified, then it is used as a content of torrent
|
||||||
// adjustAnnounceUri is true, announce URIs are adjusted using
|
// file instead. If adjustAnnounceUri is true, announce URIs are
|
||||||
// bittorrent::adjustAnnounceUri(). In this function,
|
// adjusted using bittorrent::adjustAnnounceUri(). In this function,
|
||||||
// force-sequential is ignored.
|
// force-sequential is ignored.
|
||||||
void createRequestGroupForBitTorrent
|
void createRequestGroupForBitTorrent
|
||||||
(std::vector<SharedHandle<RequestGroup> >& result,
|
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||||
const SharedHandle<Option>& option,
|
const SharedHandle<Option>& option,
|
||||||
const std::vector<std::string>& uris,
|
const std::vector<std::string>& uris,
|
||||||
|
const std::string& metaInfoUri,
|
||||||
const std::string& torrentData = "",
|
const std::string& torrentData = "",
|
||||||
bool adjustAnnounceUri = true);
|
bool adjustAnnounceUri = true);
|
||||||
|
|
||||||
|
// Create RequestGroup object using already decoded torrent metainfo
|
||||||
|
// structure. If adjustAnnounceUri is true, announce URIs are
|
||||||
|
// adjusted using bittorrent::adjustAnnounceUri(). In this function,
|
||||||
|
// force-sequential is ignored.
|
||||||
void createRequestGroupForBitTorrent
|
void createRequestGroupForBitTorrent
|
||||||
(std::vector<SharedHandle<RequestGroup> >& result,
|
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||||
const SharedHandle<Option>& option,
|
const SharedHandle<Option>& option,
|
||||||
|
|
|
@ -233,7 +233,8 @@ error_code::Value main(int argc, char* argv[])
|
||||||
showTorrentFile(op->get(PREF_TORRENT_FILE));
|
showTorrentFile(op->get(PREF_TORRENT_FILE));
|
||||||
return exitStatus;
|
return exitStatus;
|
||||||
} else {
|
} else {
|
||||||
createRequestGroupForBitTorrent(requestGroups, op, args);
|
createRequestGroupForBitTorrent(requestGroups, op, args,
|
||||||
|
op->get(PREF_TORRENT_FILE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -321,7 +321,8 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
||||||
{
|
{
|
||||||
std::vector<SharedHandle<RequestGroup> > result;
|
std::vector<SharedHandle<RequestGroup> > result;
|
||||||
|
|
||||||
createRequestGroupForBitTorrent(result, option_, auxURIs);
|
createRequestGroupForBitTorrent(result, option_, auxURIs,
|
||||||
|
option_->get(PREF_TORRENT_FILE));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||||
|
|
||||||
|
@ -344,7 +345,8 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
||||||
// no URIs are given
|
// no URIs are given
|
||||||
std::vector<SharedHandle<RequestGroup> > result;
|
std::vector<SharedHandle<RequestGroup> > result;
|
||||||
std::vector<std::string> emptyURIs;
|
std::vector<std::string> emptyURIs;
|
||||||
createRequestGroupForBitTorrent(result, option_, emptyURIs);
|
createRequestGroupForBitTorrent(result, option_, emptyURIs,
|
||||||
|
option_->get(PREF_TORRENT_FILE));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||||
SharedHandle<RequestGroup> group = result[0];
|
SharedHandle<RequestGroup> group = result[0];
|
||||||
|
@ -356,7 +358,8 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
||||||
{
|
{
|
||||||
std::vector<SharedHandle<RequestGroup> > result;
|
std::vector<SharedHandle<RequestGroup> > result;
|
||||||
|
|
||||||
createRequestGroupForBitTorrent(result, option_, auxURIs);
|
createRequestGroupForBitTorrent(result, option_, auxURIs,
|
||||||
|
option_->get(PREF_TORRENT_FILE));
|
||||||
|
|
||||||
// See --force-requencial is ignored
|
// See --force-requencial is ignored
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||||
|
|
Loading…
Reference in New Issue