cleaning up of left-overs from torrent eviction functionality

This commit is contained in:
arvidn 2016-12-22 21:27:56 -05:00 committed by Arvid Norberg
parent c1a2e7290c
commit 3f612d7e99
9 changed files with 12 additions and 82 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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<const file_storage> m_orig_files;
// the urls to the trackers

View File

@ -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<internal_file_entry>().swap(m_files);
std::vector<char const*>().swap(m_file_hashes);
std::vector<std::string>().swap(m_symlinks);
std::vector<std::time_t>().swap(m_mtime);
#ifndef TORRENT_NO_DEPRECATE
std::vector<std::int64_t>().swap(m_file_base);
#endif
std::vector<std::string>().swap(m_paths);
}
namespace aux
{

View File

@ -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<int>(piece) * std::int64_t(files.piece_length()) + offset;

View File

@ -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<web_seed_entry>().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<file_storage&>(*m_orig_files).swap(files);
}
else
{
m_files.swap(files);
}
return true;
}

View File

@ -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