*** empty log message ***

This commit is contained in:
Arvid Norberg 2005-03-04 23:45:16 +00:00
parent 77597b360d
commit 999754ee23
5 changed files with 58 additions and 45 deletions

View File

@ -2243,6 +2243,15 @@ The file format is a bencoded dictionary containing the following fields:
| | +-------------+--------------------------------------------+ |
| | |
+----------------------+--------------------------------------------------------------+
| ``file sizes`` | list where each entry corresponds to a file in the file list |
| | in the metadata. Each entry has a list of two values, the |
| | first value is the size of the file in bytes, the second |
| | is the timestamp when the last time someone wrote to it. |
| | This information is used to compare with the files on disk. |
| | All the files must match exactly this information in order |
| | to consider the resume data as current. Otherwise a full |
| | re-check is issued. |
+----------------------+--------------------------------------------------------------+
extensions

View File

@ -61,14 +61,14 @@ namespace libtorrent
class session;
std::vector<size_type> get_filesizes(
std::vector<std::pair<size_type, std::time_t> > get_filesizes(
torrent_info const& t
, boost::filesystem::path p);
bool match_filesizes(
torrent_info const& t
, boost::filesystem::path p
, std::vector<size_type> const& sizes);
, std::vector<std::pair<size_type, std::time_t> > const& sizes);
struct file_allocation_failed: std::exception
{

View File

@ -1311,25 +1311,16 @@ namespace libtorrent
// verify file sizes
std::vector<size_type> file_sizes;
std::vector<std::pair<size_type, std::time_t> > file_sizes;
entry::list_type& l = rd["file sizes"].list();
#if defined(_MSC_VER) && _MSC_VER < 1300
for (entry::list_type::iterator i = l.begin();
i != l.end();
++i)
i != l.end(); ++i)
{
file_sizes.push_back(i->integer());
file_sizes.push_back(std::pair<size_type, std::time_t>(
i->list().front().integer()
, i->list().back().integer()));
}
#else
typedef entry::integer_type const& (entry::*mem_fun_type)() const;
std::transform(
l.begin()
, l.end()
, std::back_inserter(file_sizes)
, boost::bind((mem_fun_type)&entry::integer, _1));
#endif
if ((int)tmp_pieces.size() == info.num_pieces()
&& std::find_if(tmp_pieces.begin(), tmp_pieces.end()
@ -1338,13 +1329,14 @@ namespace libtorrent
if (info.num_files() != (int)file_sizes.size())
return;
std::vector<size_type>::iterator fs = file_sizes.begin();
std::vector<std::pair<size_type, std::time_t> >::iterator
fs = file_sizes.begin();
// the resume data says we have the entire torrent
// make sure the file sizes are the right ones
for (torrent_info::file_iterator i = info.begin_files()
, end(info.end_files()); i != end; ++i, ++fs)
{
if (i->size != *fs) return;
if (i->size != fs->first) return;
}
}

View File

@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/ref.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/bind.hpp>
#include <boost/version.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
@ -74,6 +75,14 @@ namespace std
}
#endif
#if BOOST_VERSION < 103200
bool operator<(boost::filesystem::path const& lhs
, boost::filesystem::path const& rhs)
{
return lhs.string() < rhs.string();
}
#endif
using namespace boost::filesystem;
namespace pt = boost::posix_time;
using boost::bind;
@ -160,28 +169,26 @@ namespace
namespace libtorrent
{
std::vector<size_type> get_filesizes(
std::vector<std::pair<size_type, std::time_t> > get_filesizes(
const torrent_info& t
, path p)
{
p = complete(p);
std::vector<size_type> sizes;
std::vector<std::pair<size_type, std::time_t> > sizes;
for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files();
++i)
{
size_type file_size;
size_type size = 0;
std::time_t time = 0;
try
{
file f(p / get_filename(t, i->path), file::in);
f.seek(0, file::end);
file_size = f.tell();
path f = p / get_filename(t, i->path);
size = file_size(f);
time = last_write_time(f);
}
catch (file_error&)
{
file_size = 0;
}
sizes.push_back(file_size);
catch (file_error&) {}
sizes.push_back(std::make_pair(size, time));
}
return sizes;
}
@ -189,28 +196,28 @@ namespace libtorrent
bool match_filesizes(
torrent_info const& t
, path p
, std::vector<size_type> const& sizes)
, std::vector<std::pair<size_type, std::time_t> > const& sizes)
{
if ((int)sizes.size() != t.num_files()) return false;
p = complete(p);
std::vector<size_type>::const_iterator s = sizes.begin();
std::vector<std::pair<size_type, std::time_t> >::const_iterator s
= sizes.begin();
for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files();
++i, ++s)
{
size_type file_size;
size_type size = 0;
std::time_t time = 0;
try
{
file f(p / get_filename(t, i->path), file::in);
f.seek(0, file::end);
file_size = f.tell();
path f = p / get_filename(t, i->path);
size = file_size(f);
time = last_write_time(f);
}
catch (file_error&)
{
file_size = 0;
}
if (file_size != *s) return false;
catch (file_error&) {}
if (size != s->first || time != s->second)
return false;
}
return true;
}

View File

@ -464,14 +464,19 @@ namespace libtorrent
peer_list.push_back(peer);
}
std::vector<size_type> file_sizes
std::vector<std::pair<size_type, std::time_t> > file_sizes
= get_filesizes(t->torrent_file(), t->save_path());
ret["file sizes"] = entry::list_type();
std::copy(
file_sizes.begin()
, file_sizes.end()
, std::back_inserter(ret["file sizes"].list()));
entry::list_type& fl = ret["file sizes"].list();
for (std::vector<std::pair<size_type, std::time_t> >::iterator i
= file_sizes.begin(), end(file_sizes.end()); i != end; ++i)
{
entry::list_type p;
p.push_back(entry(i->first));
p.push_back(entry(i->second));
fl.push_back(entry(p));
}
return ret;
}