merged RC_1_1 into master

This commit is contained in:
arvidn 2018-03-16 10:58:17 +01:00
commit 4b144ba451
4 changed files with 62 additions and 27 deletions

View File

@ -22,6 +22,7 @@
#include "libtorrent/portmap.hpp" // for port_mapping_t
#include "libtorrent/peer_class.hpp"
#include "libtorrent/pex_flags.hpp"
#include "libtorrent/string_view.hpp"
#include <vector>
#include <map>
@ -119,6 +120,37 @@ struct tuple_to_pair
}
};
struct from_string_view
{
static PyObject* convert(lt::string_view v)
{
str ret(v.data(), v.size());
return incref(ret.ptr());
}
};
struct to_string_view
{
to_string_view()
{
converter::registry::push_back(
&convertible, &construct, type_id<lt::string_view>()
);
}
static void* convertible(PyObject* x)
{
return PyUnicode_Check(x) ? x: nullptr;
}
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
{
void* storage = ((converter::rvalue_from_python_storage<
lt::string_view>*)data)->storage.bytes;
data->convertible = new (storage) lt::string_view(PyUnicode_AS_DATA(x), PyUnicode_GET_DATA_SIZE(x));
}
};
template<typename Map>
struct map_to_dict
{
@ -379,6 +411,7 @@ void bind_converters()
to_python_converter<lt::file_flags_t, from_bitfield_flag<lt::file_flags_t>>();
to_python_converter<lt::create_flags_t, from_bitfield_flag<lt::create_flags_t>>();
to_python_converter<lt::pex_flags_t, from_bitfield_flag<lt::pex_flags_t>>();
to_python_converter<lt::string_view, from_string_view>();
// work-around types
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<

View File

@ -146,6 +146,7 @@ void bind_create_torrent()
std::string const& (file_storage::*file_storage_symlink)(file_index_t) const = &file_storage::symlink;
sha1_hash (file_storage::*file_storage_hash)(file_index_t) const = &file_storage::hash;
std::string (file_storage::*file_storage_file_path)(file_index_t, std::string const&) const = &file_storage::file_path;
string_view (file_storage::*file_storage_file_name)(file_index_t) const = &file_storage::file_name;
std::int64_t (file_storage::*file_storage_file_size)(file_index_t) const = &file_storage::file_size;
std::int64_t (file_storage::*file_storage_file_offset)(file_index_t) const = &file_storage::file_offset;
file_flags_t (file_storage::*file_storage_file_flags)(file_index_t) const = &file_storage::file_flags;
@ -170,6 +171,7 @@ void bind_create_torrent()
.def("hash", file_storage_hash)
.def("symlink", file_storage_symlink, return_value_policy<copy_const_reference>())
.def("file_path", file_storage_file_path, (arg("idx"), arg("save_path") = ""))
.def("file_name", file_storage_file_name)
.def("file_size", file_storage_file_size)
.def("file_offset", file_storage_file_offset)
.def("file_flags", file_storage_file_flags)

View File

@ -283,6 +283,7 @@ class test_torrent_info(unittest.TestCase):
f = info.files()
self.assertEqual(f.file_path(0), 'test_torrent')
self.assertEqual(f.file_name(0), 'test_torrent')
self.assertEqual(f.file_size(0), 1234)
self.assertEqual(info.total_size(), 1234)

View File

@ -89,30 +89,6 @@ namespace libtorrent {
TORRENT_ASSERT(files().num_files() > 0);
m_save_path = complete(params.path);
m_part_file_name = "." + aux::to_hex(params.info_hash) + ".parts";
file_storage const& fs = files();
// if some files have priority 0, we need to check if they exist on the
// filesystem, in which case we won't use a partfile for them.
// this is to be backwards compatible with previous versions of
// libtorrent, when part files were not supported.
for (file_index_t i(0); i < m_file_priority.end_index(); ++i)
{
if (m_file_priority[i] != dont_download || fs.pad_file_at(i))
continue;
file_status s;
std::string const file_path = files().file_path(i, m_save_path);
error_code ec;
stat_file(file_path, &s, ec);
if (!ec)
{
use_partfile(i, false);
}
else
{
need_partfile();
}
}
}
default_storage::~default_storage()
@ -262,9 +238,32 @@ namespace libtorrent {
m_file_created.resize(files().num_files(), false);
}
file_storage const& fs = files();
// if some files have priority 0, we need to check if they exist on the
// filesystem, in which case we won't use a partfile for them.
// this is to be backwards compatible with previous versions of
// libtorrent, when part files were not supported.
for (file_index_t i(0); i < m_file_priority.end_index(); ++i)
{
if (m_file_priority[i] != dont_download || fs.pad_file_at(i))
continue;
file_status s;
std::string const file_path = files().file_path(i, m_save_path);
error_code err;
stat_file(file_path, &s, err);
if (!err)
{
use_partfile(i, false);
}
else
{
need_partfile();
}
}
// first, create all missing directories
std::string last_path;
file_storage const& fs = files();
for (file_index_t file_index(0); file_index < fs.end_file(); ++file_index)
{
// ignore files that have priority 0
@ -275,7 +274,7 @@ namespace libtorrent {
}
// ignore pad files
if (files().pad_file_at(file_index)) continue;
if (fs.pad_file_at(file_index)) continue;
// this is just to see if the file exists
error_code err;
@ -296,7 +295,7 @@ namespace libtorrent {
if (files().file_size(file_index) == 0
&& err == boost::system::errc::no_such_file_or_directory)
{
std::string file_path = files().file_path(file_index, m_save_path);
std::string file_path = fs.file_path(file_index, m_save_path);
std::string dir = parent_path(file_path);
if (dir != last_path)