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)) {
|
||||
A2_LOG_INFO(fmt("Uploaded torrent data was saved as %s", filename.c_str()));
|
||||
requestOption->put(PREF_TORRENT_FILE, filename);
|
||||
createRequestGroupForBitTorrent(result, requestOption, uris);
|
||||
} else {
|
||||
A2_LOG_INFO(fmt("Uploaded torrent data was not saved."
|
||||
" Failed to write file %s", filename.c_str()));
|
||||
createRequestGroupForBitTorrent(result, requestOption,
|
||||
uris, torrentParam->s());
|
||||
filename.clear();
|
||||
}
|
||||
createRequestGroupForBitTorrent(result, requestOption, uris, filename,
|
||||
torrentParam->s());
|
||||
|
||||
if(!result.empty()) {
|
||||
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
|
||||
// RequestGroup is created with magnet URI.
|
||||
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
||||
std::vector<std::string>(), torrent, false);
|
||||
std::vector<std::string>(),
|
||||
A2STR::NIL, torrent, false);
|
||||
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
||||
if(requestGroup->getMetadataInfo()) {
|
||||
setMetadataInfo(newRgs.begin(), newRgs.end(),
|
||||
|
|
|
@ -242,13 +242,14 @@ void createRequestGroupForBitTorrent
|
|||
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||
const SharedHandle<Option>& option,
|
||||
const std::vector<std::string>& uris,
|
||||
const std::string& metaInfoUri,
|
||||
const std::string& torrentData,
|
||||
bool adjustAnnounceUri)
|
||||
{
|
||||
SharedHandle<ValueBase> torrent;
|
||||
bittorrent::ValueBaseBencodeParser parser;
|
||||
if(torrentData.empty()) {
|
||||
torrent = parseFile(parser, option->get(PREF_TORRENT_FILE));
|
||||
torrent = parseFile(parser, metaInfoUri);
|
||||
} else {
|
||||
ssize_t error;
|
||||
torrent = parser.parseFinal(torrentData.c_str(), torrentData.size(),
|
||||
|
@ -258,10 +259,7 @@ void createRequestGroupForBitTorrent
|
|||
throw DL_ABORT_EX2("Bencode decoding failed",
|
||||
error_code::BENCODE_PARSE_ERROR);
|
||||
}
|
||||
createRequestGroupForBitTorrent(result, option, uris,
|
||||
torrentData.empty() ?
|
||||
option->get(PREF_TORRENT_FILE) : "",
|
||||
torrent);
|
||||
createRequestGroupForBitTorrent(result, option, uris, metaInfoUri, torrent);
|
||||
}
|
||||
|
||||
void createRequestGroupForBitTorrent
|
||||
|
|
|
@ -54,18 +54,23 @@ class ValueBase;
|
|||
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
// Create RequestGroup object using torrent file specified by
|
||||
// torrent-file option. If non-empty torrentData is specified, then
|
||||
// it is used as a content of torrent file instead. If
|
||||
// adjustAnnounceUri is true, announce URIs are adjusted using
|
||||
// bittorrent::adjustAnnounceUri(). In this function,
|
||||
// metaInfoUri, which is treated as local file path. If non-empty
|
||||
// torrentData is specified, then it is used as a content of torrent
|
||||
// file instead. If adjustAnnounceUri is true, announce URIs are
|
||||
// adjusted using bittorrent::adjustAnnounceUri(). In this function,
|
||||
// force-sequential is ignored.
|
||||
void createRequestGroupForBitTorrent
|
||||
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||
const SharedHandle<Option>& option,
|
||||
const std::vector<std::string>& uris,
|
||||
const std::string& metaInfoUri,
|
||||
const std::string& torrentData = "",
|
||||
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
|
||||
(std::vector<SharedHandle<RequestGroup> >& result,
|
||||
const SharedHandle<Option>& option,
|
||||
|
|
|
@ -233,7 +233,8 @@ error_code::Value main(int argc, char* argv[])
|
|||
showTorrentFile(op->get(PREF_TORRENT_FILE));
|
||||
return exitStatus;
|
||||
} else {
|
||||
createRequestGroupForBitTorrent(requestGroups, op, args);
|
||||
createRequestGroupForBitTorrent(requestGroups, op, args,
|
||||
op->get(PREF_TORRENT_FILE));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -320,8 +320,9 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
|||
option_->put(PREF_BT_EXCLUDE_TRACKER, "http://tracker1");
|
||||
{
|
||||
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());
|
||||
|
||||
|
@ -344,7 +345,8 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
|||
// no URIs are given
|
||||
std::vector<SharedHandle<RequestGroup> > result;
|
||||
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());
|
||||
SharedHandle<RequestGroup> group = result[0];
|
||||
|
@ -355,8 +357,9 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
|
|||
option_->put(PREF_FORCE_SEQUENTIAL, A2_V_TRUE);
|
||||
{
|
||||
std::vector<SharedHandle<RequestGroup> > result;
|
||||
|
||||
createRequestGroupForBitTorrent(result, option_, auxURIs);
|
||||
|
||||
createRequestGroupForBitTorrent(result, option_, auxURIs,
|
||||
option_->get(PREF_TORRENT_FILE));
|
||||
|
||||
// See --force-requencial is ignored
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
|
||||
|
|
Loading…
Reference in New Issue