forked from premiere/premiere-libtorrent
storage_params cleanup
This commit is contained in:
parent
35491bc476
commit
aa842948a3
|
@ -846,11 +846,16 @@ void generate_data(char const* path, torrent_info const& ti)
|
|||
|
||||
file_pool fp;
|
||||
|
||||
storage_params params;
|
||||
params.files = &const_cast<file_storage&>(fs);
|
||||
params.mapped_files = nullptr;
|
||||
params.path = path;
|
||||
params.mode = storage_mode_sparse;
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params params{
|
||||
fs,
|
||||
nullptr,
|
||||
path,
|
||||
storage_mode_sparse,
|
||||
priorities,
|
||||
info_hash
|
||||
};
|
||||
|
||||
std::unique_ptr<storage_interface> st(default_storage_constructor(params, fp));
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/units.hpp"
|
||||
#include "libtorrent/aux_/vector.hpp"
|
||||
#include "libtorrent/sha1_hash.hpp"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
|
@ -104,12 +105,23 @@ namespace libtorrent {
|
|||
|
||||
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
|
||||
std::string path;
|
||||
std::string const& path;
|
||||
storage_mode_t mode{storage_mode_sparse};
|
||||
aux::vector<std::uint8_t, file_index_t> const* priorities = nullptr; // optional
|
||||
torrent_info const* info = nullptr; // optional
|
||||
aux::vector<std::uint8_t, file_index_t> const& priorities;
|
||||
sha1_hash const& info_hash;
|
||||
};
|
||||
|
||||
using storage_constructor_type = std::function<storage_interface*(storage_params const& params, file_pool&)>;
|
||||
|
|
|
@ -272,11 +272,16 @@ namespace libtorrent {
|
|||
counters cnt;
|
||||
disk_io_thread disk_thread(ios, cnt);
|
||||
|
||||
storage_params params;
|
||||
params.files = &t.files();
|
||||
params.mapped_files = nullptr;
|
||||
params.path = path;
|
||||
params.mode = storage_mode_sparse;
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params params{
|
||||
t.files(),
|
||||
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>());
|
||||
|
||||
|
|
|
@ -85,18 +85,16 @@ namespace libtorrent {
|
|||
|
||||
default_storage::default_storage(storage_params const& params
|
||||
, file_pool& pool)
|
||||
: storage_interface(*params.files)
|
||||
: storage_interface(params.files)
|
||||
, m_file_priority(params.priorities)
|
||||
, m_pool(pool)
|
||||
, m_allocate_files(params.mode == storage_mode_allocate)
|
||||
{
|
||||
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);
|
||||
m_save_path = complete(params.path);
|
||||
m_part_file_name = "." + (params.info
|
||||
? aux::to_hex(params.info->info_hash())
|
||||
: params.files->name()) + ".parts";
|
||||
m_part_file_name = "." + aux::to_hex(params.info_hash) + ".parts";
|
||||
}
|
||||
|
||||
default_storage::~default_storage()
|
||||
|
@ -758,7 +756,7 @@ namespace {
|
|||
|
||||
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 ------------------------------------------------------
|
||||
|
@ -810,7 +808,7 @@ namespace {
|
|||
|
||||
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
|
||||
|
|
|
@ -1582,22 +1582,15 @@ namespace libtorrent {
|
|||
|
||||
void torrent::construct_storage()
|
||||
{
|
||||
storage_params params;
|
||||
|
||||
if (&m_torrent_file->orig_files() != &m_torrent_file->files())
|
||||
{
|
||||
params.mapped_files = &m_torrent_file->files();
|
||||
params.files = &m_torrent_file->orig_files();
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
storage_params params{
|
||||
m_torrent_file->orig_files(),
|
||||
&m_torrent_file->orig_files() != &m_torrent_file->files()
|
||||
? &m_torrent_file->files() : nullptr,
|
||||
m_save_path,
|
||||
static_cast<storage_mode_t>(m_storage_mode),
|
||||
m_file_priority,
|
||||
m_info_hash
|
||||
};
|
||||
|
||||
TORRENT_ASSERT(m_storage_constructor);
|
||||
|
||||
|
|
|
@ -170,9 +170,16 @@ void generate_files(lt::torrent_info const& ti, std::string const& path
|
|||
{
|
||||
file_pool fp;
|
||||
|
||||
storage_params params;
|
||||
params.files = &ti.files();
|
||||
params.path = path;
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params params{
|
||||
ti.files(),
|
||||
nullptr,
|
||||
path,
|
||||
storage_mode_t::storage_mode_sparse,
|
||||
priorities,
|
||||
info_hash
|
||||
};
|
||||
|
||||
default_storage st(params, fp);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
storage_params p;
|
||||
p.files = &fs;
|
||||
p.path = test_path;
|
||||
p.mode = storage_mode_allocate;
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params p{
|
||||
fs,
|
||||
nullptr,
|
||||
test_path,
|
||||
storage_mode_allocate,
|
||||
priorities,
|
||||
info_hash
|
||||
};
|
||||
std::shared_ptr<default_storage> s(new default_storage(p, fp));
|
||||
s->m_settings = &set;
|
||||
|
||||
|
@ -226,10 +232,17 @@ void run_storage_tests(std::shared_ptr<torrent_info> info
|
|||
file_pool fp;
|
||||
boost::asio::io_service ios;
|
||||
disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop));
|
||||
storage_params p;
|
||||
p.path = test_path;
|
||||
p.files = &fs;
|
||||
p.mode = storage_mode;
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params p{
|
||||
fs,
|
||||
nullptr,
|
||||
test_path,
|
||||
storage_mode,
|
||||
priorities,
|
||||
info_hash
|
||||
};
|
||||
std::unique_ptr<storage_interface> s(new default_storage(p, fp));
|
||||
s->m_settings = &set;
|
||||
|
||||
|
@ -462,10 +475,17 @@ void test_check_files(std::string const& test_path
|
|||
io.set_settings(&sett);
|
||||
|
||||
disk_buffer_pool dp(16 * 1024, ios, std::bind(&nop));
|
||||
storage_params p;
|
||||
p.files = &fs;
|
||||
p.path = test_path;
|
||||
p.mode = storage_mode;
|
||||
|
||||
aux::vector<std::uint8_t, file_index_t> priorities;
|
||||
sha1_hash info_hash;
|
||||
storage_params p{
|
||||
fs,
|
||||
nullptr,
|
||||
test_path,
|
||||
storage_mode,
|
||||
priorities,
|
||||
info_hash
|
||||
};
|
||||
|
||||
auto st = io.new_torrent(default_storage_constructor, std::move(p)
|
||||
, std::shared_ptr<void>());
|
||||
|
|
Loading…
Reference in New Issue