From 07ff024e30e8ce6811d67019a64b39ee316f6bca Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 14 Apr 2018 16:47:49 +0200 Subject: [PATCH] fix conversions of resume_data field of save_resume_data_alert. make write_resume_data_buf return a byte-array. use write_resume_data_buf() in client.py instead of, the deprecated, resume_data --- bindings/python/client.py | 2 +- bindings/python/src/alert.cpp | 9 ++++++++- bindings/python/src/session.cpp | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bindings/python/client.py b/bindings/python/client.py index 6e655cb7c..4613bb9c6 100755 --- a/bindings/python/client.py +++ b/bindings/python/client.py @@ -355,7 +355,7 @@ def main(): for a in alerts: if type(a) == lt.save_resume_data_alert: print(a) - data = lt.bencode(a.resume_data) + data = lt.write_resume_data_buf(a.params) h = a.handle if h in torrents: open(os.path.join(options.save_path, torrents[h].name + '.fastresume'), 'wb').write(data) diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 1492cf4b9..6ecf6af1c 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -135,6 +135,13 @@ dict session_stats_values(session_stats_alert const& alert) return d; } +#ifndef TORRENT_NO_DEPRECATE +entry const& get_resume_data_entry(save_resume_data_alert const& self) +{ + return *self.resume_data; +} +#endif + namespace boost { // some older compilers (like msvc-12.0) end up using @@ -676,7 +683,7 @@ void bind_alert() "save_resume_data_alert", no_init) .def_readonly("params", &save_resume_data_alert::params) #ifndef TORRENT_NO_DEPRECATE - .def_readonly("resume_data", &save_resume_data_alert::resume_data) + .add_property("resume_data", make_function(get_resume_data_entry, by_value())) #endif ; diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 9ac80be16..dab759a6e 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -634,6 +634,15 @@ namespace return lt::find_metric_idx(name); } + bytes write_resume_data_buf_(add_torrent_params const& atp) + { + bytes ret; + auto buf = write_resume_data_buf(atp); + ret.arr.resize(buf.size()); + std::copy(buf.begin(), buf.end(), ret.arr.begin()); + return ret; + } + } // anonymous namespace struct dummy1 {}; @@ -1100,7 +1109,7 @@ void bind_session() def("default_settings", default_settings_wrapper); def("read_resume_data", read_resume_data_wrapper); def("write_resume_data", write_resume_data); - def("write_resume_data_buf", write_resume_data_buf); + def("write_resume_data_buf", write_resume_data_buf_); class_("stats_metric") .def_readonly("name", &stats_metric::name)