storage_params cleanup

This commit is contained in:
arvidn 2017-06-19 22:29:04 -04:00 committed by Arvid Norberg
parent 35491bc476
commit aa842948a3
7 changed files with 92 additions and 52 deletions

View File

@ -846,11 +846,16 @@ void generate_data(char const* path, torrent_info const& ti)
file_pool fp; file_pool fp;
storage_params params; aux::vector<std::uint8_t, file_index_t> priorities;
params.files = &const_cast<file_storage&>(fs); sha1_hash info_hash;
params.mapped_files = nullptr; storage_params params{
params.path = path; fs,
params.mode = storage_mode_sparse; nullptr,
path,
storage_mode_sparse,
priorities,
info_hash
};
std::unique_ptr<storage_interface> st(default_storage_constructor(params, fp)); std::unique_ptr<storage_interface> st(default_storage_constructor(params, fp));

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/units.hpp" #include "libtorrent/units.hpp"
#include "libtorrent/aux_/vector.hpp" #include "libtorrent/aux_/vector.hpp"
#include "libtorrent/sha1_hash.hpp"
#include <functional> #include <functional>
#include <string> #include <string>
@ -104,12 +105,23 @@ namespace libtorrent {
struct TORRENT_EXPORT storage_params struct TORRENT_EXPORT storage_params
{ {
file_storage const* files = nullptr; storage_params(file_storage const& f, file_storage const* mf
, std::string const& sp, storage_mode_t const sm
, aux::vector<std::uint8_t, file_index_t> const& prio
, sha1_hash const& ih)
: files(f)
, mapped_files(mf)
, path(sp)
, mode(sm)
, priorities(prio)
, info_hash(ih)
{}
file_storage const& files;
file_storage const* mapped_files = nullptr; // optional file_storage const* mapped_files = nullptr; // optional
std::string path; std::string const& path;
storage_mode_t mode{storage_mode_sparse}; storage_mode_t mode{storage_mode_sparse};
aux::vector<std::uint8_t, file_index_t> const* priorities = nullptr; // optional aux::vector<std::uint8_t, file_index_t> const& priorities;
torrent_info const* info = nullptr; // optional sha1_hash const& info_hash;
}; };
using storage_constructor_type = std::function<storage_interface*(storage_params const& params, file_pool&)>; using storage_constructor_type = std::function<storage_interface*(storage_params const& params, file_pool&)>;

View File

@ -272,11 +272,16 @@ namespace libtorrent {
counters cnt; counters cnt;
disk_io_thread disk_thread(ios, cnt); disk_io_thread disk_thread(ios, cnt);
storage_params params; aux::vector<std::uint8_t, file_index_t> priorities;
params.files = &t.files(); sha1_hash info_hash;
params.mapped_files = nullptr; storage_params params{
params.path = path; t.files(),
params.mode = storage_mode_sparse; nullptr,
path,
storage_mode_t::storage_mode_sparse,
priorities,
info_hash
};
storage_holder storage = disk_thread.new_torrent(default_storage_constructor, std::move(params), std::shared_ptr<void>()); storage_holder storage = disk_thread.new_torrent(default_storage_constructor, std::move(params), std::shared_ptr<void>());

View File

@ -85,18 +85,16 @@ namespace libtorrent {
default_storage::default_storage(storage_params const& params default_storage::default_storage(storage_params const& params
, file_pool& pool) , file_pool& pool)
: storage_interface(*params.files) : storage_interface(params.files)
, m_file_priority(params.priorities)
, m_pool(pool) , m_pool(pool)
, m_allocate_files(params.mode == storage_mode_allocate) , m_allocate_files(params.mode == storage_mode_allocate)
{ {
if (params.mapped_files) m_mapped_files.reset(new file_storage(*params.mapped_files)); if (params.mapped_files) m_mapped_files.reset(new file_storage(*params.mapped_files));
if (params.priorities) m_file_priority = *params.priorities;
TORRENT_ASSERT(files().num_files() > 0); TORRENT_ASSERT(files().num_files() > 0);
m_save_path = complete(params.path); m_save_path = complete(params.path);
m_part_file_name = "." + (params.info m_part_file_name = "." + aux::to_hex(params.info_hash) + ".parts";
? aux::to_hex(params.info->info_hash())
: params.files->name()) + ".parts";
} }
default_storage::~default_storage() default_storage::~default_storage()
@ -758,7 +756,7 @@ namespace {
storage_interface* disabled_storage_constructor(storage_params const& params, file_pool&) storage_interface* disabled_storage_constructor(storage_params const& params, file_pool&)
{ {
return new disabled_storage(*params.files); return new disabled_storage(params.files);
} }
// -- zero_storage ------------------------------------------------------ // -- zero_storage ------------------------------------------------------
@ -810,7 +808,7 @@ namespace {
storage_interface* zero_storage_constructor(storage_params const& params, file_pool&) storage_interface* zero_storage_constructor(storage_params const& params, file_pool&)
{ {
return new zero_storage(*params.files); return new zero_storage(params.files);
} }
} // namespace libtorrent } // namespace libtorrent

View File

@ -1582,22 +1582,15 @@ namespace libtorrent {
void torrent::construct_storage() void torrent::construct_storage()
{ {
storage_params params; storage_params params{
m_torrent_file->orig_files(),
if (&m_torrent_file->orig_files() != &m_torrent_file->files()) &m_torrent_file->orig_files() != &m_torrent_file->files()
{ ? &m_torrent_file->files() : nullptr,
params.mapped_files = &m_torrent_file->files(); m_save_path,
params.files = &m_torrent_file->orig_files(); static_cast<storage_mode_t>(m_storage_mode),
} m_file_priority,
else m_info_hash
{ };
params.files = &m_torrent_file->files();
params.mapped_files = nullptr;
}
params.path = m_save_path;
params.mode = static_cast<storage_mode_t>(m_storage_mode);
params.priorities = &m_file_priority;
params.info = m_torrent_file.get();
TORRENT_ASSERT(m_storage_constructor); TORRENT_ASSERT(m_storage_constructor);

View File

@ -170,9 +170,16 @@ void generate_files(lt::torrent_info const& ti, std::string const& path
{ {
file_pool fp; file_pool fp;
storage_params params; aux::vector<std::uint8_t, file_index_t> priorities;
params.files = &ti.files(); sha1_hash info_hash;
params.path = path; storage_params params{
ti.files(),
nullptr,
path,
storage_mode_t::storage_mode_sparse,
priorities,
info_hash
};
default_storage st(params, fp); default_storage st(params, fp);

View File

@ -158,10 +158,16 @@ std::shared_ptr<default_storage> setup_torrent(file_storage& fs
{ {
std::shared_ptr<torrent_info> info = setup_torrent_info(fs, buf); std::shared_ptr<torrent_info> info = setup_torrent_info(fs, buf);
storage_params p; aux::vector<std::uint8_t, file_index_t> priorities;
p.files = &fs; sha1_hash info_hash;
p.path = test_path; storage_params p{
p.mode = storage_mode_allocate; fs,
nullptr,
test_path,
storage_mode_allocate,
priorities,
info_hash
};
std::shared_ptr<default_storage> s(new default_storage(p, fp)); std::shared_ptr<default_storage> s(new default_storage(p, fp));
s->m_settings = &set; s->m_settings = &set;
@ -226,10 +232,17 @@ void run_storage_tests(std::shared_ptr<torrent_info> info
file_pool fp; file_pool fp;
boost::asio::io_service ios; boost::asio::io_service ios;
disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop)); disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop));
storage_params p;
p.path = test_path; aux::vector<std::uint8_t, file_index_t> priorities;
p.files = &fs; sha1_hash info_hash;
p.mode = storage_mode; storage_params p{
fs,
nullptr,
test_path,
storage_mode,
priorities,
info_hash
};
std::unique_ptr<storage_interface> s(new default_storage(p, fp)); std::unique_ptr<storage_interface> s(new default_storage(p, fp));
s->m_settings = &set; s->m_settings = &set;
@ -462,10 +475,17 @@ void test_check_files(std::string const& test_path
io.set_settings(&sett); io.set_settings(&sett);
disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop)); disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop));
storage_params p;
p.files = &fs; aux::vector<std::uint8_t, file_index_t> priorities;
p.path = test_path; sha1_hash info_hash;
p.mode = storage_mode; storage_params p{
fs,
nullptr,
test_path,
storage_mode,
priorities,
info_hash
};
auto st = io.new_torrent(default_storage_constructor, std::move(p) auto st = io.new_torrent(default_storage_constructor, std::move(p)
, std::shared_ptr<void>()); , std::shared_ptr<void>());