*** 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 extensions

View File

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

View File

@@ -1311,25 +1311,16 @@ namespace libtorrent
// verify file sizes // 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(); entry::list_type& l = rd["file sizes"].list();
#if defined(_MSC_VER) && _MSC_VER < 1300
for (entry::list_type::iterator i = l.begin(); for (entry::list_type::iterator i = l.begin();
i != l.end(); i != l.end(); ++i)
++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() if ((int)tmp_pieces.size() == info.num_pieces()
&& std::find_if(tmp_pieces.begin(), tmp_pieces.end() && std::find_if(tmp_pieces.begin(), tmp_pieces.end()
@@ -1338,13 +1329,14 @@ namespace libtorrent
if (info.num_files() != (int)file_sizes.size()) if (info.num_files() != (int)file_sizes.size())
return; 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 // the resume data says we have the entire torrent
// make sure the file sizes are the right ones // make sure the file sizes are the right ones
for (torrent_info::file_iterator i = info.begin_files() for (torrent_info::file_iterator i = info.begin_files()
, end(info.end_files()); i != end; ++i, ++fs) , 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/ref.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/version.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
@@ -74,6 +75,14 @@ namespace std
} }
#endif #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; using namespace boost::filesystem;
namespace pt = boost::posix_time; namespace pt = boost::posix_time;
using boost::bind; using boost::bind;
@@ -160,28 +169,26 @@ namespace
namespace libtorrent namespace libtorrent
{ {
std::vector<size_type> get_filesizes( std::vector<std::pair<size_type, std::time_t> > get_filesizes(
const torrent_info& t const torrent_info& t
, path p) , path p)
{ {
p = complete(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(); for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files(); i != t.end_files();
++i) ++i)
{ {
size_type file_size; size_type size = 0;
std::time_t time = 0;
try try
{ {
file f(p / get_filename(t, i->path), file::in); path f = p / get_filename(t, i->path);
f.seek(0, file::end); size = file_size(f);
file_size = f.tell(); time = last_write_time(f);
} }
catch (file_error&) catch (file_error&) {}
{ sizes.push_back(std::make_pair(size, time));
file_size = 0;
}
sizes.push_back(file_size);
} }
return sizes; return sizes;
} }
@@ -189,28 +196,28 @@ namespace libtorrent
bool match_filesizes( bool match_filesizes(
torrent_info const& t torrent_info const& t
, path p , 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; if ((int)sizes.size() != t.num_files()) return false;
p = complete(p); 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(); for (torrent_info::file_iterator i = t.begin_files();
i != t.end_files(); i != t.end_files();
++i, ++s) ++i, ++s)
{ {
size_type file_size; size_type size = 0;
std::time_t time = 0;
try try
{ {
file f(p / get_filename(t, i->path), file::in); path f = p / get_filename(t, i->path);
f.seek(0, file::end); size = file_size(f);
file_size = f.tell(); time = last_write_time(f);
} }
catch (file_error&) catch (file_error&) {}
{ if (size != s->first || time != s->second)
file_size = 0; return false;
}
if (file_size != *s) return false;
} }
return true; return true;
} }

View File

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