diff --git a/examples/bt-get2.cpp b/examples/bt-get2.cpp index 83f3ad030..aadcc8180 100644 --- a/examples/bt-get2.cpp +++ b/examples/bt-get2.cpp @@ -85,12 +85,7 @@ int main(int argc, char const* argv[]) try std::vector buf{std::istream_iterator(ifs) , std::istream_iterator()}; - 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); diff --git a/include/libtorrent/read_resume_data.hpp b/include/libtorrent/read_resume_data.hpp index 87c21b4d6..3db37a543 100644 --- a/include/libtorrent/read_resume_data.hpp +++ b/include/libtorrent/read_resume_data.hpp @@ -52,6 +52,8 @@ namespace libtorrent { , error_code& ec); TORRENT_EXPORT add_torrent_params read_resume_data(span 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 buffer); } #endif diff --git a/src/read_resume_data.cpp b/src/read_resume_data.cpp index 45dd779ae..983c573c5 100644 --- a/src/read_resume_data.cpp +++ b/src/read_resume_data.cpp @@ -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 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; + } } diff --git a/test/test_read_resume.cpp b/test/test_read_resume.cpp index ff67aca84..5cac08ff5 100644 --- a/test/test_read_resume.cpp +++ b/test/test_read_resume.cpp @@ -77,10 +77,7 @@ TORRENT_TEST(read_resume) std::vector 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()); diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 04374cf6e..0c92e3fa7 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -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 = "."; } diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 11e50e41b..8c4e9e743 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -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(std::cref(*t)); p.save_path = combine_path(test_path, "tmp2");