2008-05-28 10:44:40 +02:00
|
|
|
/*
|
|
|
|
|
2012-10-02 05:16:33 +02:00
|
|
|
Copyright (c) 2003-2012, Arvid Norberg
|
2008-05-28 10:44:40 +02:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libtorrent/pch.hpp"
|
|
|
|
|
|
|
|
#include "libtorrent/file_storage.hpp"
|
2012-08-26 17:26:17 +02:00
|
|
|
#include "libtorrent/string_util.hpp" // for allocate_string_copy
|
2009-10-26 02:29:39 +01:00
|
|
|
#include "libtorrent/file.hpp"
|
2008-11-30 09:12:26 +01:00
|
|
|
#include "libtorrent/utf8.hpp"
|
2009-01-11 11:32:57 +01:00
|
|
|
#include <boost/bind.hpp>
|
2009-06-22 18:13:16 +02:00
|
|
|
#include <cstdio>
|
2009-11-26 19:31:27 +01:00
|
|
|
#include <algorithm>
|
2008-05-28 10:44:40 +02:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
file_storage::file_storage()
|
2010-08-22 19:47:07 +02:00
|
|
|
: m_total_size(0)
|
2008-05-28 10:44:40 +02:00
|
|
|
, m_num_pieces(0)
|
2010-08-22 19:47:07 +02:00
|
|
|
, m_piece_length(0)
|
2008-05-28 10:44:40 +02:00
|
|
|
{}
|
|
|
|
|
2009-11-26 07:54:52 +01:00
|
|
|
void file_storage::reserve(int num_files)
|
|
|
|
{
|
|
|
|
m_files.reserve(num_files);
|
|
|
|
}
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
int file_storage::piece_size(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < num_pieces());
|
|
|
|
if (index == num_pieces()-1)
|
|
|
|
{
|
2011-12-24 21:13:51 +01:00
|
|
|
size_type size_except_last = num_pieces() - 1;
|
2012-02-27 07:26:11 +01:00
|
|
|
size_except_last *= size_type(piece_length());
|
|
|
|
size_type size = total_size() - size_except_last;
|
2008-05-28 10:44:40 +02:00
|
|
|
TORRENT_ASSERT(size > 0);
|
|
|
|
TORRENT_ASSERT(size <= piece_length());
|
|
|
|
return int(size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return piece_length();
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
void file_storage::update_path_index(internal_file_entry& e)
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
2013-06-10 00:30:02 +02:00
|
|
|
std::string fname = e.filename();
|
|
|
|
if (is_complete(fname))
|
|
|
|
{
|
|
|
|
e.path_index = -2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::string parent = parent_path(fname);
|
2013-11-17 09:02:16 +01:00
|
|
|
|
2010-11-25 00:49:22 +01:00
|
|
|
if (parent.empty())
|
|
|
|
{
|
|
|
|
e.path_index = -1;
|
2013-11-17 09:02:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent.size() >= m_name.size()
|
|
|
|
&& parent.compare(0, m_name.size(), m_name) == 0
|
|
|
|
&& (parent.size() == m_name.size()
|
|
|
|
#ifdef TORRENT_WINDOWS
|
|
|
|
|| parent[m_name.size()] == '\\'
|
|
|
|
#endif
|
|
|
|
|| parent[m_name.size()] == '/'
|
|
|
|
))
|
|
|
|
{
|
|
|
|
parent.erase(parent.begin(), parent.begin() + m_name.size()
|
|
|
|
+ (m_name.size() == parent.size()?0:1));
|
|
|
|
e.no_root_dir = false;
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-17 09:02:16 +01:00
|
|
|
e.no_root_dir = true;
|
|
|
|
}
|
2010-11-25 00:49:22 +01:00
|
|
|
|
2013-11-17 09:02:16 +01:00
|
|
|
// do we already have this path in the path list?
|
|
|
|
std::vector<std::string>::reverse_iterator p
|
|
|
|
= std::find(m_paths.rbegin(), m_paths.rend(), parent);
|
|
|
|
|
|
|
|
if (p == m_paths.rend())
|
|
|
|
{
|
|
|
|
// no, we don't. add it
|
|
|
|
e.path_index = m_paths.size();
|
|
|
|
m_paths.push_back(parent);
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
2013-11-17 09:02:16 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// yes we do. use it
|
|
|
|
e.path_index = p.base() - m_paths.begin() - 1;
|
|
|
|
}
|
|
|
|
e.set_name(filename(e.filename()).c_str());
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
|
2012-03-19 07:06:52 +01:00
|
|
|
file_entry::file_entry(): offset(0), size(0), file_base(0)
|
|
|
|
, mtime(0), pad_file(false), hidden_attribute(false)
|
|
|
|
, executable_attribute(false)
|
|
|
|
, symlink_attribute(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
file_entry::~file_entry() {}
|
|
|
|
|
2013-11-17 09:02:16 +01:00
|
|
|
internal_file_entry::~internal_file_entry()
|
|
|
|
{
|
|
|
|
if (name_len == name_is_owned) free((void*)name);
|
|
|
|
}
|
2010-11-25 00:49:22 +01:00
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
internal_file_entry::internal_file_entry(internal_file_entry const& fe)
|
2010-11-25 00:49:22 +01:00
|
|
|
: name(0)
|
|
|
|
, offset(fe.offset)
|
|
|
|
, symlink_index(fe.symlink_index)
|
|
|
|
, size(fe.size)
|
|
|
|
, name_len(fe.name_len)
|
|
|
|
, pad_file(fe.pad_file)
|
|
|
|
, hidden_attribute(fe.hidden_attribute)
|
|
|
|
, executable_attribute(fe.executable_attribute)
|
|
|
|
, symlink_attribute(fe.symlink_attribute)
|
2013-11-17 09:02:16 +01:00
|
|
|
, no_root_dir(fe.no_root_dir)
|
2010-11-25 00:49:22 +01:00
|
|
|
, path_index(fe.path_index)
|
|
|
|
{
|
2011-06-06 09:47:29 +02:00
|
|
|
set_name(fe.filename().c_str());
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
internal_file_entry& internal_file_entry::operator=(internal_file_entry const& fe)
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
offset = fe.offset;
|
|
|
|
size = fe.size;
|
|
|
|
path_index = fe.path_index;
|
|
|
|
symlink_index = fe.symlink_index;
|
|
|
|
pad_file = fe.pad_file;
|
|
|
|
hidden_attribute = fe.hidden_attribute;
|
|
|
|
executable_attribute = fe.executable_attribute;
|
|
|
|
symlink_attribute = fe.symlink_attribute;
|
2013-11-17 09:02:16 +01:00
|
|
|
no_root_dir = fe.no_root_dir;
|
2011-06-06 09:47:29 +02:00
|
|
|
set_name(fe.filename().c_str());
|
2010-11-25 00:49:22 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-10-05 06:18:24 +02:00
|
|
|
// if borrow_chars >= 0, don't take ownership over n, just
|
|
|
|
// point to it. It points to borrow_chars number of characters.
|
|
|
|
// if borrow_chars == -1, n is a null terminated string that
|
|
|
|
// should be copied
|
|
|
|
void internal_file_entry::set_name(char const* n, bool borrow_string, int string_len)
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
2013-10-05 06:18:24 +02:00
|
|
|
TORRENT_ASSERT(string_len >= 0);
|
|
|
|
|
|
|
|
// we have limited space in the length field. truncate string
|
|
|
|
// if it's too long
|
|
|
|
if (string_len >= name_is_owned) string_len = name_is_owned - 1;
|
|
|
|
|
|
|
|
// free the current string, before assigning the new one
|
|
|
|
if (name_len == name_is_owned) free((void*)name);
|
|
|
|
if (n == NULL)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(borrow_string == false);
|
|
|
|
name = NULL;
|
|
|
|
}
|
|
|
|
else if (borrow_string)
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
2013-10-05 06:18:24 +02:00
|
|
|
name = n;
|
|
|
|
name_len = string_len;
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-05 06:18:24 +02:00
|
|
|
name = allocate_string_copy(n);
|
|
|
|
name_len = name_is_owned;
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
std::string internal_file_entry::filename() const
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
2013-10-05 06:18:24 +02:00
|
|
|
if (name_len != name_is_owned) return std::string(name, name_len);
|
2010-11-25 00:49:22 +01:00
|
|
|
return name ? name : "";
|
|
|
|
}
|
|
|
|
|
2009-10-26 02:29:39 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2013-08-02 07:03:22 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2008-11-30 09:12:26 +01:00
|
|
|
void file_storage::set_name(std::wstring const& n)
|
|
|
|
{
|
|
|
|
std::string utf8;
|
|
|
|
wchar_utf8(n, utf8);
|
|
|
|
m_name = utf8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_storage::rename_file(int index, std::wstring const& new_filename)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
std::string utf8;
|
|
|
|
wchar_utf8(new_filename, utf8);
|
2010-11-25 00:49:22 +01:00
|
|
|
m_files[index].set_name(utf8.c_str());
|
|
|
|
update_path_index(m_files[index]);
|
2008-11-30 09:12:26 +01:00
|
|
|
}
|
|
|
|
|
2009-10-26 02:29:39 +01:00
|
|
|
void file_storage::add_file(std::wstring const& file, size_type size, int flags
|
|
|
|
, std::time_t mtime, std::string const& symlink_path)
|
2009-03-31 10:12:35 +02:00
|
|
|
{
|
|
|
|
std::string utf8;
|
2009-10-26 02:29:39 +01:00
|
|
|
wchar_utf8(file, utf8);
|
2009-07-01 10:35:45 +02:00
|
|
|
add_file(utf8, size, flags, mtime, symlink_path);
|
2009-03-31 10:12:35 +02:00
|
|
|
}
|
2013-08-02 07:03:22 +02:00
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2009-10-26 02:29:39 +01:00
|
|
|
#endif // TORRENT_USE_WSTRING
|
2009-03-31 10:12:35 +02:00
|
|
|
|
|
|
|
void file_storage::rename_file(int index, std::string const& new_filename)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
2010-11-25 00:49:22 +01:00
|
|
|
m_files[index].set_name(new_filename.c_str());
|
|
|
|
update_path_index(m_files[index]);
|
2009-03-31 10:12:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
void file_storage::rename_file_borrow(int index, char const* new_filename, int len)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
2013-10-05 06:18:24 +02:00
|
|
|
m_files[index].set_name(new_filename, true, len);
|
2013-08-12 09:30:57 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 02:12:36 +01:00
|
|
|
namespace
|
|
|
|
{
|
2010-11-29 06:44:29 +01:00
|
|
|
bool compare_file_offset(internal_file_entry const& lhs, internal_file_entry const& rhs)
|
2009-01-14 02:12:36 +01:00
|
|
|
{
|
2009-01-14 07:55:28 +01:00
|
|
|
return lhs.offset < rhs.offset;
|
2009-01-14 02:12:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2013-10-07 09:45:36 +02:00
|
|
|
file_storage::iterator file_storage::file_at_offset_deprecated(size_type offset) const
|
2009-07-04 06:58:24 +02:00
|
|
|
{
|
|
|
|
// find the file iterator and file offset
|
2010-11-29 06:44:29 +01:00
|
|
|
internal_file_entry target;
|
2009-07-04 06:58:24 +02:00
|
|
|
target.offset = offset;
|
|
|
|
TORRENT_ASSERT(!compare_file_offset(target, m_files.front()));
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
std::vector<internal_file_entry>::const_iterator file_iter = std::upper_bound(
|
2013-10-14 04:25:21 +02:00
|
|
|
begin_deprecated(), end_deprecated(), target, compare_file_offset);
|
2009-07-04 06:58:24 +02:00
|
|
|
|
2013-10-14 04:25:21 +02:00
|
|
|
TORRENT_ASSERT(file_iter != begin_deprecated());
|
2009-07-04 06:58:24 +02:00
|
|
|
--file_iter;
|
|
|
|
return file_iter;
|
|
|
|
}
|
2013-10-14 04:25:21 +02:00
|
|
|
|
|
|
|
file_storage::iterator file_storage::file_at_offset(size_type offset) const
|
|
|
|
{
|
|
|
|
return file_at_offset_deprecated(offset);
|
|
|
|
}
|
2013-08-12 09:30:57 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int file_storage::file_index_at_offset(size_type offset) const
|
|
|
|
{
|
|
|
|
// find the file iterator and file offset
|
|
|
|
internal_file_entry target;
|
|
|
|
target.offset = offset;
|
|
|
|
TORRENT_ASSERT(!compare_file_offset(target, m_files.front()));
|
|
|
|
|
|
|
|
std::vector<internal_file_entry>::const_iterator file_iter = std::upper_bound(
|
|
|
|
m_files.begin(), m_files.end(), target, compare_file_offset);
|
|
|
|
|
|
|
|
TORRENT_ASSERT(file_iter != m_files.begin());
|
|
|
|
--file_iter;
|
|
|
|
return file_iter - m_files.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
char const* file_storage::file_name_ptr(int index) const
|
|
|
|
{
|
|
|
|
return m_files[index].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int file_storage::file_name_len(int index) const
|
|
|
|
{
|
2013-10-05 06:18:24 +02:00
|
|
|
if (m_files[index].name_len == internal_file_entry::name_is_owned)
|
|
|
|
return -1;
|
2013-08-12 09:30:57 +02:00
|
|
|
return m_files[index].name_len;
|
|
|
|
}
|
2009-07-04 06:58:24 +02:00
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
std::vector<file_slice> file_storage::map_block(int piece, size_type offset
|
2009-01-14 02:12:36 +01:00
|
|
|
, int size) const
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(num_files() > 0);
|
|
|
|
std::vector<file_slice> ret;
|
|
|
|
|
2009-01-14 07:55:28 +01:00
|
|
|
if (m_files.empty()) return ret;
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
// find the file iterator and file offset
|
2010-11-29 06:44:29 +01:00
|
|
|
internal_file_entry target;
|
2009-01-14 02:12:36 +01:00
|
|
|
target.offset = piece * (size_type)m_piece_length + offset;
|
|
|
|
TORRENT_ASSERT(target.offset + size <= m_total_size);
|
2009-01-14 07:55:28 +01:00
|
|
|
TORRENT_ASSERT(!compare_file_offset(target, m_files.front()));
|
2009-01-14 02:12:36 +01:00
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
std::vector<internal_file_entry>::const_iterator file_iter = std::upper_bound(
|
2013-08-12 09:30:57 +02:00
|
|
|
m_files.begin(), m_files.end(), target, compare_file_offset);
|
2008-05-28 10:44:40 +02:00
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
TORRENT_ASSERT(file_iter != m_files.begin());
|
2009-01-14 07:55:28 +01:00
|
|
|
--file_iter;
|
2009-01-14 02:12:36 +01:00
|
|
|
|
2009-01-14 08:39:02 +01:00
|
|
|
size_type file_offset = target.offset - file_iter->offset;
|
2009-01-14 02:12:36 +01:00
|
|
|
for (; size > 0; file_offset -= file_iter->size, ++file_iter)
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
2013-08-12 09:30:57 +02:00
|
|
|
TORRENT_ASSERT(file_iter != m_files.end());
|
2008-05-28 10:44:40 +02:00
|
|
|
if (file_offset < file_iter->size)
|
|
|
|
{
|
|
|
|
file_slice f;
|
2013-08-12 09:30:57 +02:00
|
|
|
f.file_index = file_iter - m_files.begin();
|
|
|
|
f.offset = file_offset + file_base(f.file_index);
|
2013-10-05 06:18:24 +02:00
|
|
|
f.size = (std::min)(size_type(file_iter->size) - file_offset, (size_type)size);
|
2011-02-21 06:24:41 +01:00
|
|
|
TORRENT_ASSERT(f.size <= size);
|
|
|
|
size -= int(f.size);
|
2008-05-28 10:44:40 +02:00
|
|
|
file_offset += f.size;
|
|
|
|
ret.push_back(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TORRENT_ASSERT(size >= 0);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2010-11-29 06:44:29 +01:00
|
|
|
|
|
|
|
file_entry file_storage::at(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
file_entry ret;
|
|
|
|
internal_file_entry const& ife = m_files[index];
|
2013-08-12 09:30:57 +02:00
|
|
|
ret.path = file_path(index);
|
2010-11-29 06:44:29 +01:00
|
|
|
ret.offset = ife.offset;
|
|
|
|
ret.size = ife.size;
|
2013-08-12 09:30:57 +02:00
|
|
|
ret.file_base = file_base(index);
|
|
|
|
ret.mtime = mtime(index);
|
2010-11-29 06:44:29 +01:00
|
|
|
ret.pad_file = ife.pad_file;
|
|
|
|
ret.hidden_attribute = ife.hidden_attribute;
|
|
|
|
ret.executable_attribute = ife.executable_attribute;
|
|
|
|
ret.symlink_attribute = ife.symlink_attribute;
|
2013-11-17 09:02:16 +01:00
|
|
|
if (ife.symlink_index != internal_file_entry::not_a_symlink)
|
|
|
|
ret.symlink_path = symlink(index);
|
2013-08-12 09:30:57 +02:00
|
|
|
ret.filehash = hash(index);
|
2010-11-29 06:44:29 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
peer_request file_storage::map_file(int file_index, size_type file_offset
|
|
|
|
, int size) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(file_index < num_files());
|
|
|
|
TORRENT_ASSERT(file_index >= 0);
|
|
|
|
|
|
|
|
peer_request ret;
|
2013-02-28 04:29:33 +01:00
|
|
|
if (file_index < 0 || file_index >= num_files())
|
|
|
|
{
|
|
|
|
ret.piece = m_num_pieces;
|
|
|
|
ret.start = 0;
|
|
|
|
ret.length = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_type offset = file_offset + this->file_offset(file_index);
|
|
|
|
|
|
|
|
if (offset >= total_size())
|
|
|
|
{
|
|
|
|
ret.piece = m_num_pieces;
|
|
|
|
ret.start = 0;
|
|
|
|
ret.length = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret.piece = int(offset / piece_length());
|
|
|
|
ret.start = int(offset % piece_length());
|
|
|
|
ret.length = size;
|
|
|
|
if (offset + size > total_size())
|
|
|
|
ret.length = total_size() - offset;
|
|
|
|
}
|
2008-05-28 10:44:40 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-26 02:29:39 +01:00
|
|
|
void file_storage::add_file(std::string const& file, size_type size, int flags
|
|
|
|
, std::time_t mtime, std::string const& symlink_path)
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(size >= 0);
|
2012-02-07 04:45:13 +01:00
|
|
|
if (size < 0) size = 0;
|
2009-10-26 02:29:39 +01:00
|
|
|
if (!has_parent_path(file))
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
|
|
|
// you have already added at least one file with a
|
|
|
|
// path to the file (branch_path), which means that
|
|
|
|
// all the other files need to be in the same top
|
|
|
|
// directory as the first file.
|
|
|
|
TORRENT_ASSERT(m_files.empty());
|
2009-10-26 02:29:39 +01:00
|
|
|
m_name = file;
|
2008-05-28 10:44:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_files.empty())
|
2009-10-26 02:29:39 +01:00
|
|
|
m_name = split_path(file).c_str();
|
2008-05-28 10:44:40 +02:00
|
|
|
}
|
2009-10-26 02:29:39 +01:00
|
|
|
TORRENT_ASSERT(m_name == split_path(file).c_str());
|
2010-11-29 06:44:29 +01:00
|
|
|
m_files.push_back(internal_file_entry());
|
|
|
|
internal_file_entry& e = m_files.back();
|
2010-11-25 00:49:22 +01:00
|
|
|
e.set_name(file.c_str());
|
2009-01-11 23:27:43 +01:00
|
|
|
e.size = size;
|
|
|
|
e.offset = m_total_size;
|
2010-10-16 17:24:45 +02:00
|
|
|
e.pad_file = (flags & pad_file) != 0;
|
|
|
|
e.hidden_attribute = (flags & attribute_hidden) != 0;
|
|
|
|
e.executable_attribute = (flags & attribute_executable) != 0;
|
|
|
|
e.symlink_attribute = (flags & attribute_symlink) != 0;
|
2010-11-15 06:10:36 +01:00
|
|
|
if (e.symlink_attribute)
|
|
|
|
{
|
|
|
|
e.symlink_index = m_symlinks.size();
|
|
|
|
m_symlinks.push_back(symlink_path);
|
|
|
|
}
|
2010-11-25 00:49:22 +01:00
|
|
|
if (mtime)
|
|
|
|
{
|
|
|
|
if (m_mtime.size() < m_files.size()) m_mtime.resize(m_files.size());
|
|
|
|
m_mtime[m_files.size() - 1] = mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
update_path_index(e);
|
2008-05-28 10:44:40 +02:00
|
|
|
m_total_size += size;
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
void file_storage::add_file(file_entry const& ent, char const* filehash)
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
2012-02-25 11:49:50 +01:00
|
|
|
TORRENT_ASSERT(ent.size >= 0);
|
2010-11-29 06:44:29 +01:00
|
|
|
if (!has_parent_path(ent.path))
|
2009-01-11 23:27:43 +01:00
|
|
|
{
|
|
|
|
// you have already added at least one file with a
|
|
|
|
// path to the file (branch_path), which means that
|
|
|
|
// all the other files need to be in the same top
|
|
|
|
// directory as the first file.
|
|
|
|
TORRENT_ASSERT(m_files.empty());
|
2010-11-29 06:44:29 +01:00
|
|
|
m_name = ent.path;
|
2009-01-11 23:27:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_files.empty())
|
2010-11-29 06:44:29 +01:00
|
|
|
m_name = split_path(ent.path).c_str();
|
2009-01-11 23:27:43 +01:00
|
|
|
}
|
2010-11-29 06:44:29 +01:00
|
|
|
internal_file_entry ife(ent);
|
2013-08-12 09:30:57 +02:00
|
|
|
int file_index = m_files.size();
|
2010-11-29 06:44:29 +01:00
|
|
|
m_files.push_back(ife);
|
|
|
|
internal_file_entry& e = m_files.back();
|
2009-01-11 23:27:43 +01:00
|
|
|
e.offset = m_total_size;
|
2012-02-25 11:49:50 +01:00
|
|
|
m_total_size += e.size;
|
2010-11-15 06:10:36 +01:00
|
|
|
if (filehash)
|
|
|
|
{
|
2010-11-25 00:49:22 +01:00
|
|
|
if (m_file_hashes.size() < m_files.size()) m_file_hashes.resize(m_files.size());
|
|
|
|
m_file_hashes[m_files.size() - 1] = filehash;
|
2010-11-15 06:10:36 +01:00
|
|
|
}
|
2010-11-29 06:44:29 +01:00
|
|
|
if (!ent.symlink_path.empty())
|
2010-11-15 06:10:36 +01:00
|
|
|
{
|
|
|
|
e.symlink_index = m_symlinks.size();
|
2010-11-29 06:44:29 +01:00
|
|
|
m_symlinks.push_back(ent.symlink_path);
|
2010-11-15 06:10:36 +01:00
|
|
|
}
|
2010-11-29 06:44:29 +01:00
|
|
|
if (ent.mtime)
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
if (m_mtime.size() < m_files.size()) m_mtime.resize(m_files.size());
|
2010-11-29 06:44:29 +01:00
|
|
|
m_mtime[m_files.size() - 1] = ent.mtime;
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
2013-08-12 09:30:57 +02:00
|
|
|
if (ent.file_base) set_file_base(file_index, ent.file_base);
|
2010-11-25 00:49:22 +01:00
|
|
|
update_path_index(e);
|
|
|
|
}
|
|
|
|
|
2012-03-26 18:07:55 +02:00
|
|
|
sha1_hash file_storage::hash(int index) const
|
|
|
|
{
|
|
|
|
if (index >= int(m_file_hashes.size())) return sha1_hash(0);
|
|
|
|
return sha1_hash(m_file_hashes[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string const& file_storage::symlink(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
internal_file_entry const& fe = m_files[index];
|
|
|
|
TORRENT_ASSERT(fe.symlink_index < int(m_symlinks.size()));
|
|
|
|
return m_symlinks[fe.symlink_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t file_storage::mtime(int index) const
|
|
|
|
{
|
|
|
|
if (index >= int(m_mtime.size())) return 0;
|
|
|
|
return m_mtime[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_storage::set_file_base(int index, size_type off)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
2013-03-17 23:05:09 +01:00
|
|
|
if (int(m_file_base.size()) <= index) m_file_base.resize(index + 1, 0);
|
2012-03-26 18:07:55 +02:00
|
|
|
m_file_base[index] = off;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_type file_storage::file_base(int index) const
|
|
|
|
{
|
|
|
|
if (index >= int(m_file_base.size())) return 0;
|
|
|
|
return m_file_base[index];
|
|
|
|
}
|
|
|
|
|
2013-06-10 00:30:02 +02:00
|
|
|
std::string file_storage::file_path(int index, std::string const& save_path) const
|
2012-03-26 18:07:55 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
internal_file_entry const& fe = m_files[index];
|
2013-11-17 09:02:16 +01:00
|
|
|
return file_path(fe, save_path);
|
2012-03-26 18:07:55 +02:00
|
|
|
}
|
|
|
|
|
2012-08-31 04:31:37 +02:00
|
|
|
std::string file_storage::file_name(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
internal_file_entry const& fe = m_files[index];
|
|
|
|
return fe.filename();
|
|
|
|
}
|
|
|
|
|
2012-03-26 18:07:55 +02:00
|
|
|
size_type file_storage::file_size(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
return m_files[index].size;
|
|
|
|
}
|
|
|
|
|
2012-09-30 22:55:12 +02:00
|
|
|
bool file_storage::pad_file_at(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
return m_files[index].pad_file;
|
|
|
|
}
|
|
|
|
|
2012-09-29 19:46:41 +02:00
|
|
|
size_type file_storage::file_offset(int index) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
|
|
|
return m_files[index].offset;
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
int file_storage::file_flags(int index) const
|
|
|
|
{
|
|
|
|
internal_file_entry const& fe = m_files[index];
|
|
|
|
return (fe.pad_file ? flag_pad_file : 0)
|
|
|
|
| (fe.hidden_attribute ? flag_hidden : 0)
|
|
|
|
| (fe.executable_attribute ? flag_executable : 0)
|
|
|
|
| (fe.symlink_attribute ? flag_symlink : 0);
|
|
|
|
}
|
|
|
|
|
2013-08-12 05:18:43 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2010-11-29 06:44:29 +01:00
|
|
|
sha1_hash file_storage::hash(internal_file_entry const& fe) const
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
int index = &fe - &m_files[0];
|
2011-02-14 02:59:01 +01:00
|
|
|
if (index >= int(m_file_hashes.size())) return sha1_hash(0);
|
2010-11-25 00:49:22 +01:00
|
|
|
return sha1_hash(m_file_hashes[index]);
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
std::string const& file_storage::symlink(internal_file_entry const& fe) const
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(fe.symlink_index < int(m_symlinks.size()));
|
|
|
|
return m_symlinks[fe.symlink_index];
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
time_t file_storage::mtime(internal_file_entry const& fe) const
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
int index = &fe - &m_files[0];
|
2011-02-14 02:59:01 +01:00
|
|
|
if (index >= int(m_mtime.size())) return 0;
|
2010-11-25 00:49:22 +01:00
|
|
|
return m_mtime[index];
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
int file_storage::file_index(internal_file_entry const& fe) const
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
int index = &fe - &m_files[0];
|
2011-02-14 02:59:01 +01:00
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
2010-11-25 00:49:22 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
void file_storage::set_file_base(internal_file_entry const& fe, size_type off)
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
int index = &fe - &m_files[0];
|
2011-02-14 02:59:01 +01:00
|
|
|
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
2013-03-17 23:05:09 +01:00
|
|
|
if (int(m_file_base.size()) <= index) m_file_base.resize(index + 1, 0);
|
2010-11-25 00:49:22 +01:00
|
|
|
m_file_base[index] = off;
|
|
|
|
}
|
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
size_type file_storage::file_base(internal_file_entry const& fe) const
|
2010-11-25 00:49:22 +01:00
|
|
|
{
|
|
|
|
int index = &fe - &m_files[0];
|
2011-02-14 02:59:01 +01:00
|
|
|
if (index >= int(m_file_base.size())) return 0;
|
2010-11-25 00:49:22 +01:00
|
|
|
return m_file_base[index];
|
|
|
|
}
|
|
|
|
|
2013-11-17 09:02:16 +01:00
|
|
|
std::string file_storage::file_path(internal_file_entry const& fe
|
|
|
|
, std::string const& save_path) const
|
2012-03-26 18:07:55 +02:00
|
|
|
{
|
2013-06-10 00:30:02 +02:00
|
|
|
TORRENT_ASSERT(fe.path_index >= -2 && fe.path_index < int(m_paths.size()));
|
|
|
|
// -2 means this is an absolute path filename
|
|
|
|
if (fe.path_index == -2) return fe.filename();
|
|
|
|
|
|
|
|
// -1 means no path
|
|
|
|
if (fe.path_index == -1) return combine_path(save_path, fe.filename());
|
|
|
|
|
2013-11-17 09:02:16 +01:00
|
|
|
if (fe.no_root_dir)
|
|
|
|
return combine_path(save_path
|
|
|
|
, combine_path(m_paths[fe.path_index]
|
|
|
|
, fe.filename()));
|
|
|
|
|
|
|
|
return combine_path(save_path
|
|
|
|
, combine_path(m_name
|
|
|
|
, combine_path(m_paths[fe.path_index]
|
|
|
|
, fe.filename())));
|
2012-03-26 18:07:55 +02:00
|
|
|
}
|
|
|
|
|
2012-08-31 04:31:37 +02:00
|
|
|
std::string file_storage::file_name(internal_file_entry const& fe) const
|
|
|
|
{
|
|
|
|
return fe.filename();
|
|
|
|
}
|
|
|
|
|
2012-03-26 18:07:55 +02:00
|
|
|
size_type file_storage::file_size(internal_file_entry const& fe) const
|
|
|
|
{
|
|
|
|
return fe.size;
|
|
|
|
}
|
|
|
|
|
2012-09-30 22:55:12 +02:00
|
|
|
bool file_storage::pad_file_at(internal_file_entry const& fe) const
|
|
|
|
{
|
|
|
|
return fe.pad_file;
|
|
|
|
}
|
|
|
|
|
2012-09-29 19:46:41 +02:00
|
|
|
size_type file_storage::file_offset(internal_file_entry const& fe) const
|
|
|
|
{
|
|
|
|
return fe.offset;
|
|
|
|
}
|
2013-08-12 09:30:57 +02:00
|
|
|
|
|
|
|
file_entry file_storage::at(file_storage::iterator i) const
|
|
|
|
{ return at(i - begin()); }
|
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2012-09-29 19:46:41 +02:00
|
|
|
|
2010-11-29 06:44:29 +01:00
|
|
|
bool compare_file_entry_size(internal_file_entry const& fe1, internal_file_entry const& fe2)
|
2010-11-25 00:49:22 +01:00
|
|
|
{ return fe1.size < fe2.size; }
|
|
|
|
|
|
|
|
void file_storage::reorder_file(int index, int dst)
|
|
|
|
{
|
2012-08-12 21:16:20 +02:00
|
|
|
TORRENT_ASSERT(index < int(m_files.size()));
|
|
|
|
TORRENT_ASSERT(dst < int(m_files.size()));
|
|
|
|
TORRENT_ASSERT(dst < index);
|
|
|
|
|
2012-08-12 21:46:24 +02:00
|
|
|
std::iter_swap(m_files.begin() + index, m_files.begin() + dst);
|
2010-11-25 00:49:22 +01:00
|
|
|
if (!m_mtime.empty())
|
|
|
|
{
|
2012-08-12 21:16:20 +02:00
|
|
|
TORRENT_ASSERT(m_mtime.size() == m_files.size());
|
2012-08-12 21:46:24 +02:00
|
|
|
if (int(m_mtime.size()) < index) m_mtime.resize(index+1, 0);
|
|
|
|
std::iter_swap(m_mtime.begin() + dst, m_mtime.begin() + index);
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
if (!m_file_hashes.empty())
|
|
|
|
{
|
2012-08-12 21:16:20 +02:00
|
|
|
TORRENT_ASSERT(m_file_hashes.size() == m_files.size());
|
2012-08-12 21:46:24 +02:00
|
|
|
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);
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
|
|
|
if (!m_file_base.empty())
|
|
|
|
{
|
2012-08-12 21:16:20 +02:00
|
|
|
TORRENT_ASSERT(m_file_base.size() == m_files.size());
|
2013-03-17 23:05:09 +01:00
|
|
|
if (int(m_file_base.size()) < index) m_file_base.resize(index + 1, 0);
|
2012-08-12 21:46:24 +02:00
|
|
|
std::iter_swap(m_file_base.begin() + dst, m_file_base.begin() + index);
|
2010-11-25 00:49:22 +01:00
|
|
|
}
|
2008-05-28 10:44:40 +02:00
|
|
|
}
|
2009-01-11 11:32:57 +01:00
|
|
|
|
2012-08-12 23:18:38 +02:00
|
|
|
void file_storage::optimize(int pad_file_limit, int alignment)
|
2009-01-11 11:32:57 +01:00
|
|
|
{
|
|
|
|
// it doesn't make any sense to pad files that
|
2012-08-12 23:18:38 +02:00
|
|
|
// are smaller than one block
|
|
|
|
if (pad_file_limit >= 0 && pad_file_limit < 0x4000)
|
|
|
|
pad_file_limit = 0x4000;
|
|
|
|
|
|
|
|
// also, it doesn't make any sense to pad files
|
|
|
|
// that are smaller than the alignment, since they
|
|
|
|
// won't get aligned anyway; they are used as padding
|
2009-01-11 11:32:57 +01:00
|
|
|
if (pad_file_limit >= 0 && pad_file_limit < alignment)
|
|
|
|
pad_file_limit = alignment;
|
|
|
|
|
|
|
|
size_type off = 0;
|
|
|
|
int padding_file = 0;
|
2010-11-29 06:44:29 +01:00
|
|
|
for (std::vector<internal_file_entry>::iterator i = m_files.begin();
|
2009-01-11 11:32:57 +01:00
|
|
|
i != m_files.end(); ++i)
|
|
|
|
{
|
2011-03-22 03:27:54 +01:00
|
|
|
if ((off & (alignment-1)) == 0)
|
|
|
|
{
|
|
|
|
// this file position is aligned, pick the largest
|
|
|
|
// available file to put here
|
|
|
|
std::vector<internal_file_entry>::iterator best_match
|
|
|
|
= std::max_element(i, m_files.end()
|
|
|
|
, &compare_file_entry_size);
|
|
|
|
|
|
|
|
if (best_match != i)
|
|
|
|
{
|
2013-08-12 09:30:57 +02:00
|
|
|
int index = best_match - m_files.begin();
|
|
|
|
int cur_index = i - m_files.begin();
|
2011-11-16 03:27:28 +01:00
|
|
|
reorder_file(index, cur_index);
|
|
|
|
i = m_files.begin() + cur_index;
|
2011-03-22 03:27:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pad_file_limit >= 0
|
2009-01-11 23:27:43 +01:00
|
|
|
&& i->size > pad_file_limit
|
|
|
|
&& i->pad_file == false)
|
2009-01-11 11:32:57 +01:00
|
|
|
{
|
|
|
|
// if we have pad files enabled, and this file is
|
|
|
|
// not piece-aligned and the file size exceeds the
|
2009-01-11 23:27:43 +01:00
|
|
|
// limit, and it's not a padding file itself.
|
|
|
|
// so add a padding file in front of it
|
2009-01-11 11:32:57 +01:00
|
|
|
int pad_size = alignment - (off & (alignment-1));
|
|
|
|
|
|
|
|
// find the largest file that fits in pad_size
|
2010-11-29 06:44:29 +01:00
|
|
|
std::vector<internal_file_entry>::iterator best_match = m_files.end();
|
|
|
|
for (std::vector<internal_file_entry>::iterator j = i+1; j < m_files.end(); ++j)
|
2009-01-11 11:32:57 +01:00
|
|
|
{
|
|
|
|
if (j->size > pad_size) continue;
|
|
|
|
if (best_match == m_files.end() || j->size > best_match->size)
|
|
|
|
best_match = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_match != m_files.end())
|
|
|
|
{
|
|
|
|
// we found one
|
2011-02-21 07:57:03 +01:00
|
|
|
// We cannot have found i, because i->size > pad_file_limit
|
|
|
|
// which is forced to be no less than alignment. We only
|
|
|
|
// look for files <= pad_size, which never is greater than
|
|
|
|
// alignment
|
|
|
|
TORRENT_ASSERT(best_match != i);
|
2013-08-12 09:30:57 +02:00
|
|
|
int index = best_match - m_files.begin();
|
|
|
|
int cur_index = i - m_files.begin();
|
2011-11-16 03:27:28 +01:00
|
|
|
reorder_file(index, cur_index);
|
|
|
|
i = m_files.begin() + cur_index;
|
2009-01-11 11:32:57 +01:00
|
|
|
i->offset = off;
|
|
|
|
off += i->size;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we could not find a file that fits in pad_size
|
|
|
|
// add a padding file
|
2011-02-21 07:57:03 +01:00
|
|
|
// note that i will be set to point to the
|
|
|
|
// new pad file. Once we're done adding it, we need
|
|
|
|
// to increment i to point to the current file again
|
2012-08-12 21:46:24 +02:00
|
|
|
// first add the pad file to the end of the file list
|
|
|
|
// then swap it in place. This minimizes the amount
|
|
|
|
// of copying of internal_file_entry, which is somewhat
|
|
|
|
// expensive (until we have move semantics)
|
2013-08-12 09:30:57 +02:00
|
|
|
int cur_index = i - m_files.begin();
|
2012-08-12 21:46:24 +02:00
|
|
|
int index = m_files.size();
|
|
|
|
m_files.push_back(internal_file_entry());
|
|
|
|
internal_file_entry& e = m_files.back();
|
|
|
|
// i may have been invalidated, refresh it
|
|
|
|
i = m_files.begin() + cur_index;
|
|
|
|
e.size = pad_size;
|
|
|
|
e.offset = off;
|
2010-11-25 00:49:22 +01:00
|
|
|
char name[30];
|
2011-03-30 18:04:24 +02:00
|
|
|
snprintf(name, sizeof(name), ".____padding_file/%d", padding_file);
|
2011-11-25 10:45:28 +01:00
|
|
|
std::string path = combine_path(m_name, name);
|
2012-08-12 21:46:24 +02:00
|
|
|
e.set_name(path.c_str());
|
|
|
|
e.pad_file = true;
|
2009-01-11 11:32:57 +01:00
|
|
|
off += pad_size;
|
|
|
|
++padding_file;
|
2012-08-12 21:16:20 +02:00
|
|
|
|
2012-08-12 21:46:24 +02:00
|
|
|
if (!m_mtime.empty()) m_mtime.resize(index + 1, 0);
|
|
|
|
if (!m_file_hashes.empty()) m_file_hashes.resize(index + 1, NULL);
|
|
|
|
if (!m_file_base.empty()) m_file_base.resize(index + 1, 0);
|
2012-08-12 21:16:20 +02:00
|
|
|
|
2012-08-12 21:46:24 +02:00
|
|
|
reorder_file(index, cur_index);
|
2012-08-12 21:16:20 +02:00
|
|
|
|
2012-08-12 23:18:38 +02:00
|
|
|
TORRENT_ASSERT((off & (alignment-1)) == 0);
|
|
|
|
continue;
|
2009-01-11 11:32:57 +01:00
|
|
|
}
|
|
|
|
i->offset = off;
|
|
|
|
off += i->size;
|
|
|
|
}
|
|
|
|
m_total_size = off;
|
|
|
|
}
|
2008-05-28 10:44:40 +02:00
|
|
|
}
|
|
|
|
|