fix ABI compatibility issue introduced with preformatted entry type

This commit is contained in:
arvidn 2017-02-12 17:55:34 -05:00 committed by Arvid Norberg
parent 194bbb0bac
commit cbd1c26a11
6 changed files with 44 additions and 8 deletions

View File

@ -1,3 +1,4 @@
* fix ABI compatibility issue introduced with preformatted entry type
* add web_seed_name_lookup_retry to session_settings
* slightly improve proxy settings backwards compatibility
* add function to get default settings

View File

@ -196,7 +196,7 @@ void bind_create_torrent()
class_<create_torrent>("create_torrent", no_init)
.def(init<file_storage&>())
.def(init<torrent_info const&>(arg("ti")))
.def(init<torrent_info const&, int>((arg("ti"), arg("version") = LIBTORRENT_VERSION_NUM)))
.def(init<file_storage&, int, int, int>((arg("storage"), arg("piece_size") = 0
, arg("pad_file_limit") = -1, arg("flags") = int(libtorrent::create_torrent::optimize_alignment))))

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/storage.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/file.hpp" // for combine_path etc.
#include "libtorrent/version.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
@ -170,10 +171,13 @@ namespace libtorrent
// ``alignment`` is used when pad files are enabled. This is the size
// eligible files are aligned to. The default is -1, which means the
// piece size of the torrent.
// The ``use_preformatted`` parameter can be set to true to preserve
// invalid encoding of the .torrent file.
create_torrent(file_storage& fs, int piece_size = 0
, int pad_file_limit = -1, int flags = optimize_alignment
, int alignment = -1);
create_torrent(torrent_info const& ti);
create_torrent(torrent_info const& ti, bool use_preformatted);
// internal
~create_torrent();
@ -298,6 +302,8 @@ namespace libtorrent
private:
void load_from_torrent_info(torrent_info const& ti, bool const use_preformatted);
file_storage& m_files;
// if m_info_dict is initialized, it is
// used instead of m_files to generate

View File

@ -382,6 +382,23 @@ namespace libtorrent
, m_merkle_torrent(ti.is_merkle_torrent())
, m_include_mtime(false)
, m_include_symlinks(false)
{
load_from_torrent_info(ti, false);
}
create_torrent::create_torrent(torrent_info const& ti, bool const use_preformatted)
: m_files(const_cast<file_storage&>(ti.files()))
, m_creation_date(time(0))
, m_multifile(ti.num_files() > 1)
, m_private(ti.priv())
, m_merkle_torrent(ti.is_merkle_torrent())
, m_include_mtime(false)
, m_include_symlinks(false)
{
load_from_torrent_info(ti, use_preformatted);
}
void create_torrent::load_from_torrent_info(torrent_info const& ti, bool const use_preformatted)
{
TORRENT_ASSERT(ti.is_valid());
TORRENT_ASSERT(ti.num_pieces() > 0);
@ -418,9 +435,16 @@ namespace libtorrent
m_piece_hash.resize(m_files.num_pieces());
for (int i = 0; i < num_pieces(); ++i) set_hash(i, ti.hash_for_piece(i));
boost::shared_array<char> const info = ti.metadata();
int const size = ti.metadata_size();
m_info_dict.preformatted().assign(&info[0], &info[0] + size);
if (use_preformatted)
{
boost::shared_array<char> const info = ti.metadata();
int const size = ti.metadata_size();
m_info_dict.preformatted().assign(&info[0], &info[0] + size);
}
else
{
m_info_dict = bdecode(&ti.metadata()[0], &ti.metadata()[0] + ti.metadata_size());
}
m_info_hash = ti.info_hash();
}

View File

@ -7215,9 +7215,14 @@ namespace libtorrent
{
if (m_magnet_link || (m_save_resume_flags & torrent_handle::save_info_dict))
{
boost::shared_array<char> const info = torrent_file().metadata();
int const size = torrent_file().metadata_size();
ret["info"].preformatted().assign(&info[0], &info[0] + size);
ret["info"] = bdecode(&torrent_file().metadata()[0]
, &torrent_file().metadata()[0] + torrent_file().metadata_size());
// TODO: re-enable this code once there's a non-inlined encoder function. Or
// perhaps this should not be used until saving resume_data via
// add_torrent_params and a free function, similar to read_resume_data
// boost::shared_array<char> const info = torrent_file().metadata();
// int const size = torrent_file().metadata_size();
// ret["info"].preformatted().assign(&info[0], &info[0] + size);
}
}

View File

@ -49,7 +49,7 @@ TORRENT_TEST(create_verbatim_torrent)
lt::torrent_info info(test_torrent, sizeof(test_torrent) - 1);
lt::create_torrent t(info);
lt::create_torrent t(info, true);
std::vector<char> buffer;
lt::bencode(std::back_inserter(buffer), t.generate());