forked from premiere/premiere-libtorrent
make throwing versions of read_resume_data
This commit is contained in:
parent
e612fee995
commit
2d99e994c3
|
@ -85,12 +85,7 @@ int main(int argc, char const* argv[]) try
|
|||
std::vector<char> buf{std::istream_iterator<char>(ifs)
|
||||
, std::istream_iterator<char>()};
|
||||
|
||||
lt::error_code ec;
|
||||
lt::add_torrent_params atp = lt::read_resume_data(buf, ec);
|
||||
if (ec) {
|
||||
std::cerr << "failed to read resume data: " << ec.message() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
lt::add_torrent_params atp = lt::read_resume_data(buf);
|
||||
lt::add_torrent_params magnet = lt::parse_magnet_uri(argv[1]);
|
||||
if (atp.info_hash != magnet.info_hash) {
|
||||
atp = std::move(magnet);
|
||||
|
|
|
@ -52,6 +52,8 @@ namespace libtorrent {
|
|||
, error_code& ec);
|
||||
TORRENT_EXPORT add_torrent_params read_resume_data(span<char const> buffer
|
||||
, error_code& ec);
|
||||
TORRENT_EXPORT add_torrent_params read_resume_data(bdecode_node const& rd);
|
||||
TORRENT_EXPORT add_torrent_params read_resume_data(span<char const> buffer);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -354,4 +354,23 @@ namespace {
|
|||
|
||||
return read_resume_data(rd, ec);
|
||||
}
|
||||
|
||||
add_torrent_params read_resume_data(bdecode_node const& rd)
|
||||
{
|
||||
error_code ec;
|
||||
auto ret = read_resume_data(rd, ec);
|
||||
if (ec) throw system_error(ec);
|
||||
return ret;
|
||||
}
|
||||
|
||||
add_torrent_params read_resume_data(span<char const> buffer)
|
||||
{
|
||||
error_code ec;
|
||||
bdecode_node rd = bdecode(buffer, ec);
|
||||
if (ec) throw system_error(ec);
|
||||
|
||||
auto ret = read_resume_data(rd, ec);
|
||||
if (ec) throw system_error(ec);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,10 +77,7 @@ TORRENT_TEST(read_resume)
|
|||
std::vector<char> resume_data;
|
||||
bencode(std::back_inserter(resume_data), rd);
|
||||
|
||||
error_code ec;
|
||||
add_torrent_params atp = read_resume_data(resume_data, ec);
|
||||
|
||||
TEST_CHECK(!ec);
|
||||
add_torrent_params atp = read_resume_data(resume_data);
|
||||
|
||||
TEST_EQUAL(atp.info_hash, sha1_hash("abcdefghijklmnopqrst"));
|
||||
TEST_EQUAL(atp.have_pieces.size(), 6);
|
||||
|
@ -165,9 +162,7 @@ TORRENT_TEST(read_resume_mismatching_torrent)
|
|||
|
||||
// the info-hash field does not match the torrent in the "info" field, so it
|
||||
// will be ignored
|
||||
error_code ec;
|
||||
add_torrent_params atp = read_resume_data(resume_data, ec);
|
||||
TEST_CHECK(!ec);
|
||||
add_torrent_params atp = read_resume_data(resume_data);
|
||||
TEST_CHECK(!atp.ti);
|
||||
}
|
||||
|
||||
|
@ -213,9 +208,7 @@ TORRENT_TEST(read_resume_torrent)
|
|||
|
||||
// the info-hash field does not match the torrent in the "info" field, so it
|
||||
// will be ignored
|
||||
error_code ec;
|
||||
add_torrent_params atp = read_resume_data(resume_data, ec);
|
||||
TEST_CHECK(!ec);
|
||||
add_torrent_params atp = read_resume_data(resume_data);
|
||||
TEST_CHECK(atp.ti);
|
||||
|
||||
TEST_EQUAL(atp.ti->info_hash(), ti->info_hash());
|
||||
|
|
|
@ -150,9 +150,7 @@ torrent_handle test_resume_flags(lt::session& ses
|
|||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(rd, ec);
|
||||
TEST_CHECK(!ec);
|
||||
p = read_resume_data(rd);
|
||||
}
|
||||
|
||||
p.ti = ti;
|
||||
|
@ -243,9 +241,7 @@ void test_piece_priorities(bool test_deprecated = false)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(resume_data, ec);
|
||||
TEST_CHECK(!ec);
|
||||
p = read_resume_data(resume_data);
|
||||
p.ti = ti;
|
||||
p.save_path = ".";
|
||||
}
|
||||
|
@ -851,9 +847,7 @@ void test_zero_file_prio(bool test_deprecated = false, bool mix_prios = false)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
error_code ec;
|
||||
p = read_resume_data(resume_data, ec);
|
||||
TEST_CHECK(!ec);
|
||||
p = read_resume_data(resume_data);
|
||||
p.ti = ti;
|
||||
p.save_path = ".";
|
||||
}
|
||||
|
|
|
@ -747,8 +747,7 @@ void test_fastresume(bool const test_deprecated)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
p = read_resume_data(resume_data, ec);
|
||||
TEST_CHECK(!ec);
|
||||
p = read_resume_data(resume_data);
|
||||
}
|
||||
|
||||
p.flags &= ~torrent_flags::paused;
|
||||
|
@ -928,8 +927,7 @@ void test_rename_file_fastresume(bool test_deprecated)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
p = read_resume_data(resume_data, ec);
|
||||
TEST_CHECK(!ec);
|
||||
p = read_resume_data(resume_data);
|
||||
}
|
||||
p.ti = std::make_shared<torrent_info>(std::cref(*t));
|
||||
p.save_path = combine_path(test_path, "tmp2");
|
||||
|
|
Loading…
Reference in New Issue