From 3f612d7e99e535611329d51e6ebf8b7c14a4c76f Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 22 Dec 2016 21:27:56 -0500 Subject: [PATCH] cleaning up of left-overs from torrent eviction functionality --- bindings/python/src/session.cpp | 2 +- include/libtorrent/add_torrent_params.hpp | 5 ++- include/libtorrent/aux_/session_impl.hpp | 2 - include/libtorrent/file_storage.hpp | 12 ------ include/libtorrent/torrent_info.hpp | 11 +++--- src/file_storage.cpp | 15 -------- src/storage.cpp | 1 - src/torrent_info.cpp | 45 +---------------------- test/test_torrent_info.cpp | 1 - 9 files changed, 12 insertions(+), 82 deletions(-) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 80b009b91..21854c6b7 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -646,11 +646,11 @@ void bind_session() .value("flag_update_subscribe", add_torrent_params::flag_update_subscribe) .value("flag_super_seeding", add_torrent_params::flag_super_seeding) .value("flag_sequential_download", add_torrent_params::flag_sequential_download) - .value("flag_pinned", add_torrent_params::flag_pinned) .value("flag_stop_when_ready", add_torrent_params::flag_stop_when_ready) .value("flag_override_trackers", add_torrent_params::flag_override_trackers) .value("flag_override_web_seeds", add_torrent_params::flag_override_web_seeds) #ifndef TORRENT_NO_DEPRECATE + .value("flag_pinned", add_torrent_params::flag_pinned) .value("flag_override_resume_data", add_torrent_params::flag_override_resume_data) .value("flag_merge_resume_trackers", add_torrent_params::flag_merge_resume_trackers) .value("flag_use_resume_save_path", add_torrent_params::flag_use_resume_save_path) diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index 087f66664..db0d3d2a6 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -183,10 +183,12 @@ namespace libtorrent // the torrent handle immediately after adding it. flag_sequential_download = 0x800, +#ifndef TORRENT_NO_DEPRECATE // indicates that this torrent should never be unloaded from RAM, even // if unloading torrents are allowed in general. Setting this makes // the torrent exempt from loading/unloading management. flag_pinned = 0x1000, +#endif // the stop when ready flag. Setting this flag is equivalent to calling // torrent_handle::stop_when_ready() immediately after the torrent is @@ -252,10 +254,11 @@ namespace libtorrent #endif // internal - default_flags = flag_pinned | flag_update_subscribe + default_flags = flag_update_subscribe | flag_auto_managed | flag_paused | flag_apply_ip_filter | flag_need_save_resume #ifndef TORRENT_NO_DEPRECATE + | flag_pinned | flag_merge_resume_http_seeds | flag_merge_resume_trackers #endif diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 22c9618c9..f66837761 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -1229,8 +1229,6 @@ namespace libtorrent #endif #ifndef TORRENT_NO_DEPRECATE - // if this function is set, it indicates that torrents are allowed - // to be unloaded. If it isn't, torrents will never be unloaded user_load_function_t m_user_load_torrent; #endif diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 72fd049b4..78b151102 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -417,7 +417,6 @@ namespace libtorrent { using std::swap; swap(ti.m_files, m_files); - swap(ti.m_num_files, m_num_files); swap(ti.m_file_hashes, m_file_hashes); swap(ti.m_symlinks, m_symlinks); swap(ti.m_mtime, m_mtime); @@ -431,13 +430,6 @@ namespace libtorrent swap(ti.m_piece_length, m_piece_length); } - // deallocates most of the memory used by this - // instance, leaving it only partially usable - void unload(); - - // returns true when populated with at least one file - bool is_loaded() const { return !m_files.empty(); } - // if pad_file_limit >= 0, files larger than that limit will be padded, // default is to not add any padding (-1). The alignment specifies the // alignment files should be padded to. This defaults to the piece size @@ -639,10 +631,6 @@ namespace libtorrent // the sum of all file sizes std::int64_t m_total_size; - - // the number of files. This is used when - // the torrent is unloaded - int m_num_files; }; namespace aux { diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index da2a58f38..c243b3ccb 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -386,13 +386,12 @@ namespace libtorrent return m_files.map_file(file, offset, size); } - // load and unload this torrent info - void load(char const* buffer, int size, error_code& ec); - void unload(); - #ifndef TORRENT_NO_DEPRECATE // ------- start deprecation ------- -// these functions will be removed in a future version + // deprecated in 1.2 + void load(char const*, int, error_code&) {} + void unload() {} + TORRENT_DEPRECATED explicit torrent_info(entry const& torrent_file); // ------- end deprecation ------- @@ -552,6 +551,8 @@ namespace libtorrent // if m_files is modified, it is first copied into // m_orig_files so that the original name and // filenames are preserved. + // the original filenames are required to build URLs for web seeds for + // instance copy_ptr m_orig_files; // the urls to the trackers diff --git a/src/file_storage.cpp b/src/file_storage.cpp index e45e9396c..865b1c4e5 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -59,7 +59,6 @@ namespace libtorrent : m_piece_length(0) , m_num_pieces(0) , m_total_size(0) - , m_num_files(0) {} file_storage::~file_storage() = default; @@ -610,7 +609,6 @@ namespace libtorrent m_mtime[last_file()] = std::time_t(mtime); } - ++m_num_files; m_total_size += e.size; } @@ -1084,7 +1082,6 @@ namespace libtorrent int const cur_index = int(i - m_files.begin()); int const index = int(m_files.size()); m_files.push_back(internal_file_entry()); - ++m_num_files; internal_file_entry& e = m_files.back(); // i may have been invalidated, refresh it i = m_files.begin() + cur_index; @@ -1108,18 +1105,6 @@ namespace libtorrent if (index != cur_index) reorder_file(index, cur_index); } - void file_storage::unload() - { - std::vector().swap(m_files); - std::vector().swap(m_file_hashes); - std::vector().swap(m_symlinks); - std::vector().swap(m_mtime); -#ifndef TORRENT_NO_DEPRECATE - std::vector().swap(m_file_base); -#endif - std::vector().swap(m_paths); - } - namespace aux { diff --git a/src/storage.cpp b/src/storage.cpp index fe219c070..d6d3c5a6d 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1133,7 +1133,6 @@ namespace libtorrent const int size = bufs_size(bufs); TORRENT_ASSERT(size > 0); - TORRENT_ASSERT(files.is_loaded()); // find the file iterator and file offset std::int64_t const torrent_offset = static_cast(piece) * std::int64_t(files.piece_length()) + offset; diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 807bc51c4..ff76671c9 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -985,37 +985,6 @@ namespace libtorrent torrent_info::~torrent_info() = default; - void torrent_info::load(char const* buffer, int size, error_code& ec) - { - bdecode_node e; - if (bdecode(buffer, buffer + size, e, ec) != 0) - return; - - if (!parse_torrent_file(e, ec, 0)) - return; - } - - void torrent_info::unload() - { - TORRENT_ASSERT(m_info_section.unique()); - - m_info_section.reset(); - m_info_section_size = 0; - - // if we have orig_files, we have to keep - // m_files around, since it means we have - // remapped files, and we won't be able to - // restore that from just reloading the - // torrent file - if (m_orig_files) m_orig_files.reset(); - else m_files.unload(); - - m_piece_hashes = nullptr; - std::vector().swap(m_web_seeds); - - TORRENT_ASSERT(!is_loaded()); - } - sha1_hash torrent_info::hash_for_piece(piece_index_t const index) const { return sha1_hash(hash_for_piece_ptr(index)); } @@ -1225,19 +1194,7 @@ namespace libtorrent // now, commit the files structure we just parsed out // into the torrent_info object. - // if we already have an m_files that's populated, it - // indicates that we unloaded this torrent_info ones - // and we had modifications to the files, so we unloaded - // the orig_files. In that case, the orig files is what - // needs to be restored - if (m_files.is_loaded()) { - m_orig_files.reset(new file_storage); - const_cast(*m_orig_files).swap(files); - } - else - { - m_files.swap(files); - } + m_files.swap(files); return true; } diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 148361ccd..a1c735bb3 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -174,7 +174,6 @@ test_failing_torrent_t test_error_torrents[] = // TODO: torrent with an SSL cert // TODO: torrent with attributes (executable and hidden) // TODO: torrent_info::add_tracker -// TODO: torrent_info::unload // TODO: torrent_info constructor that takes an invalid bencoded buffer // TODO: verify_encoding with a string that triggers character replacement