From c4a294e88a5f43ab4fd9d1ef42a4dbeaac1d9fc2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 17 Feb 2015 04:53:49 +0000 Subject: [PATCH] deprecate file_base feature in file_storage/torrent_info --- ChangeLog | 1 + include/libtorrent/file_storage.hpp | 20 +++++++-------- src/file_storage.cpp | 38 ++++++++++++++++++----------- src/storage.cpp | 6 ++++- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index a513e6f7e..4cfe1fd96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * deprecate file_base feature in file_storage/torrent_info * improve piece picker support for reverse picking (used for snubbed peers) to not cause priority inversion for regular peers * improve piece picker to better support torrents with very large pieces diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 49e1f808d..161a33822 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -402,7 +402,9 @@ namespace libtorrent swap(ti.m_file_hashes, m_file_hashes); swap(ti.m_symlinks, m_symlinks); swap(ti.m_mtime, m_mtime); +#ifndef TORRENT_NO_DEPRECATE swap(ti.m_file_base, m_file_base); +#endif swap(ti.m_paths, m_paths); swap(ti.m_name, m_name); swap(ti.m_total_size, m_total_size); @@ -496,16 +498,6 @@ namespace libtorrent // to file at ``index``. int file_flags(int index) const; - // The file base of a file is the offset within the file on the filsystem - // where it starts to write. For the most part, this is 0. It's possible - // to map several files (in the torrent) into a single file on the - // filesystem by making them all point to the same filename, but with - // different file bases, so that they don't overlap. - // torrent_info::remap_files() can be used to use a new file layout. - // TODO: 3 deprecate the file_base feature - boost::int64_t file_base(int index) const; - void set_file_base(int index, boost::int64_t off); - // returns the index of the file at the given offset in the torrent int file_index_at_offset(boost::int64_t offset) const; @@ -516,6 +508,12 @@ namespace libtorrent int file_name_len(int index) const; #ifndef TORRENT_NO_DEPRECATE + // deprecated in 1.1 + TORRENT_DEPRECATED_PREFIX + boost::int64_t file_base(int index) const TORRENT_DEPRECATED; + TORRENT_DEPRECATED_PREFIX + void set_file_base(int index, boost::int64_t off) TORRENT_DEPRECATED; + // these were deprecated in 1.0. Use the versions that take an index instead TORRENT_DEPRECATED_PREFIX sha1_hash hash(internal_file_entry const& fe) const TORRENT_DEPRECATED; @@ -583,10 +581,12 @@ namespace libtorrent // index in m_files std::vector m_mtime; +#ifndef TORRENT_NO_DEPRECATE // if any file has a non-zero file base (i.e. multiple // files residing in the same physical file at different // offsets) std::vector m_file_base; +#endif // all unique paths files have. The internal_file_entry::path_index // points into this array. The paths don't include the root directory diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 369cd88fd..75194865e 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -398,7 +398,11 @@ namespace libtorrent { file_slice f; f.file_index = file_iter - m_files.begin(); - f.offset = file_offset + file_base(f.file_index); + f.offset = file_offset +#ifndef TORRENT_NO_DEPRECATE + + file_base(f.file_index) +#endif + ; f.size = (std::min)(boost::uint64_t(file_iter->size) - file_offset, boost::uint64_t(size)); TORRENT_ASSERT(f.size <= size); size -= int(f.size); @@ -563,19 +567,6 @@ namespace libtorrent return m_mtime[index]; } - void file_storage::set_file_base(int index, boost::int64_t off) - { - TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size())); - if (int(m_file_base.size()) <= index) m_file_base.resize(index + 1, 0); - m_file_base[index] = off; - } - - boost::int64_t file_storage::file_base(int index) const - { - if (index >= int(m_file_base.size())) return 0; - return m_file_base[index]; - } - namespace { template @@ -731,6 +722,19 @@ namespace libtorrent } #ifndef TORRENT_NO_DEPRECATE + void file_storage::set_file_base(int index, boost::int64_t off) + { + TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size())); + if (int(m_file_base.size()) <= index) m_file_base.resize(index + 1, 0); + m_file_base[index] = off; + } + + boost::int64_t file_storage::file_base(int index) const + { + if (index >= int(m_file_base.size())) return 0; + return m_file_base[index]; + } + sha1_hash file_storage::hash(internal_file_entry const& fe) const { int index = &fe - &m_files[0]; @@ -826,12 +830,14 @@ namespace libtorrent if (int(m_file_hashes.size()) < index) m_file_hashes.resize(index + 1, NULL); std::iter_swap(m_file_hashes.begin() + dst, m_file_hashes.begin() + index); } +#ifndef TORRENT_NO_DEPRECATE if (!m_file_base.empty()) { TORRENT_ASSERT(m_file_base.size() == m_files.size()); if (int(m_file_base.size()) < index) m_file_base.resize(index + 1, 0); std::iter_swap(m_file_base.begin() + dst, m_file_base.begin() + index); } +#endif // TORRENT_DEPRECATED } void file_storage::optimize(int pad_file_limit, int alignment) @@ -930,7 +936,9 @@ namespace libtorrent if (!m_mtime.empty()) m_mtime.resize(index + 1, 0); if (!m_file_hashes.empty()) m_file_hashes.resize(index + 1, NULL); +#ifndef TORRENT_NO_DEPRECATE if (!m_file_base.empty()) m_file_base.resize(index + 1, 0); +#endif reorder_file(index, cur_index); @@ -949,7 +957,9 @@ namespace libtorrent 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); } } diff --git a/src/storage.cpp b/src/storage.cpp index fc8b8adf8..a28e984eb 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1192,7 +1192,11 @@ namespace libtorrent } } - boost::int64_t adjusted_offset = files().file_base(file_index) + file_offset; + boost::int64_t adjusted_offset = +#ifndef TORRENT_NO_DEPRECATE + files().file_base(file_index) + +#endif + file_offset; #ifdef TORRENT_DISK_STATS int flags = ((op.mode & file::rw_mask) == file::read_only) ? op_read : op_write;