diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index b32251244..18936d660 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -846,11 +846,16 @@ void generate_data(char const* path, torrent_info const& ti) file_pool fp; - storage_params params; - params.files = &const_cast(fs); - params.mapped_files = nullptr; - params.path = path; - params.mode = storage_mode_sparse; + aux::vector priorities; + sha1_hash info_hash; + storage_params params{ + fs, + nullptr, + path, + storage_mode_sparse, + priorities, + info_hash + }; std::unique_ptr st(default_storage_constructor(params, fp)); diff --git a/include/libtorrent/storage_defs.hpp b/include/libtorrent/storage_defs.hpp index aab116e16..a2863a216 100644 --- a/include/libtorrent/storage_defs.hpp +++ b/include/libtorrent/storage_defs.hpp @@ -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 #include @@ -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 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 const* priorities = nullptr; // optional - torrent_info const* info = nullptr; // optional + aux::vector const& priorities; + sha1_hash const& info_hash; }; using storage_constructor_type = std::function; diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 69db4bbd3..b4752b767 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -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 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()); diff --git a/src/storage.cpp b/src/storage.cpp index 2f1009a41..0d9bb70c2 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -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 diff --git a/src/torrent.cpp b/src/torrent.cpp index d35e49f5d..302879afe 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -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(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(m_storage_mode), + m_file_priority, + m_info_hash + }; TORRENT_ASSERT(m_storage_constructor); diff --git a/test/make_torrent.cpp b/test/make_torrent.cpp index 37e9283f9..a943dc925 100644 --- a/test/make_torrent.cpp +++ b/test/make_torrent.cpp @@ -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 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); diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 115acde97..08dfb2a90 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -158,10 +158,16 @@ std::shared_ptr setup_torrent(file_storage& fs { std::shared_ptr info = setup_torrent_info(fs, buf); - storage_params p; - p.files = &fs; - p.path = test_path; - p.mode = storage_mode_allocate; + aux::vector priorities; + sha1_hash info_hash; + storage_params p{ + fs, + nullptr, + test_path, + storage_mode_allocate, + priorities, + info_hash + }; std::shared_ptr s(new default_storage(p, fp)); s->m_settings = &set; @@ -226,10 +232,17 @@ void run_storage_tests(std::shared_ptr 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 priorities; + sha1_hash info_hash; + storage_params p{ + fs, + nullptr, + test_path, + storage_mode, + priorities, + info_hash + }; std::unique_ptr 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 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());