lt sync 3090

This commit is contained in:
Andrew Resch 2008-12-26 22:47:24 +00:00
parent f5a6736617
commit 45e3f12a49
5 changed files with 31 additions and 15 deletions

View File

@ -93,7 +93,13 @@ namespace libtorrent
~torrent_info();
file_storage const& files() const { return m_files; }
file_storage& files() { return m_files; }
file_storage const& orig_files() const { return m_orig_files ? *m_orig_files : m_files; }
void rename_file(int index, std::string const& new_filename)
{
copy_on_write();
m_files.rename_file(index, new_filename);
}
void add_tracker(std::string const& url, int tier = 0);
std::vector<announce_entry> const& trackers() const { return m_urls; }
@ -131,6 +137,7 @@ namespace libtorrent
// these functions will be removed in a future version
torrent_info(entry const& torrent_file) TORRENT_DEPRECATED;
void print(std::ostream& os) const TORRENT_DEPRECATED;
file_storage& files() TORRENT_DEPRECATED { return m_files; }
// ------- end deprecation -------
#endif
@ -188,10 +195,16 @@ namespace libtorrent
private:
void copy_on_write();
bool parse_torrent_file(lazy_entry const& libtorrent, std::string& error);
file_storage m_files;
// if m_files is modified, it is first copied into
// m_orig_files so that the original name and
// filenames are preserved.
boost::shared_ptr<const file_storage> m_orig_files;
// the urls to the trackers
std::vector<announce_entry> m_urls;
std::vector<std::string> m_url_seeds;

View File

@ -1046,7 +1046,7 @@ namespace aux {
peer_connection* p = (*i).get();
++i;
// ignore connections that already have a torrent, since they
// are ticket through the torrents' second_ticket
// are ticked through the torrents' second_tick
if (!p->associated_torrent().expired()) continue;
if (m_last_tick - p->connected_time() > seconds(m_settings.handshake_timeout))
p->disconnect("timeout: incoming connection");
@ -1070,8 +1070,6 @@ namespace aux {
torrent_map::iterator least_recently_scraped = m_torrents.begin();
int num_paused_auto_managed = 0;
// check each torrent for tracker updates
// TODO: do this in a timer-event in each torrent instead
for (torrent_map::iterator i = m_torrents.begin();
i != m_torrents.end();)
{
@ -1374,7 +1372,7 @@ namespace aux {
{
torrent* t = *i;
if (!t->is_paused() && !is_active(t, settings())
&& hard_limit > 0 && total_running < m_max_uploads)
&& hard_limit > 0)
{
--hard_limit;
++total_running;
@ -1403,7 +1401,7 @@ namespace aux {
{
torrent* t = *i;
if (!t->is_paused() && !is_active(t, settings())
&& hard_limit > 0 && total_running < m_max_uploads)
&& hard_limit > 0)
{
--hard_limit;
++total_running;
@ -1612,8 +1610,6 @@ namespace aux {
if (m_listen_interface.port() != 0) open_listen_port();
}
ptime timer = time_now();
do
{
error_code ec;

View File

@ -1674,7 +1674,7 @@ namespace libtorrent
{
if (alerts().should_post<file_renamed_alert>())
alerts().post_alert(file_renamed_alert(get_handle(), j.str, j.piece));
m_torrent_file->files().rename_file(j.piece, j.str);
m_torrent_file->rename_file(j.piece, j.str);
}
else
{
@ -2592,7 +2592,7 @@ namespace libtorrent
{
std::string new_filename = mapped_files->list_string_value_at(i);
if (new_filename.empty()) continue;
m_torrent_file->files().rename_file(i, new_filename);
m_torrent_file->rename_file(i, new_filename);
}
}

View File

@ -330,12 +330,19 @@ namespace libtorrent
torrent_info::~torrent_info()
{}
void torrent_info::copy_on_write()
{
if (m_orig_files) return;
m_orig_files.reset(new file_storage(m_files));
}
void torrent_info::swap(torrent_info& ti)
{
using std::swap;
m_urls.swap(ti.m_urls);
m_url_seeds.swap(ti.m_url_seeds);
m_files.swap(ti.m_files);
m_orig_files.swap(ti.m_orig_files);
m_nodes.swap(ti.m_nodes);
swap(m_info_hash, ti.m_info_hash);
swap(m_creation_date, ti.m_creation_date);

View File

@ -243,7 +243,7 @@ namespace libtorrent
}
else
{
std::vector<file_slice> files = info.files().map_block(r.piece, r.start
std::vector<file_slice> files = info.orig_files().map_block(r.piece, r.start
, r.length);
for (std::vector<file_slice>::iterator i = files.begin();
@ -255,13 +255,13 @@ namespace libtorrent
if (using_proxy)
{
request += m_url;
std::string path = info.files().at(f.file_index).path.string();
std::string path = info.orig_files().at(f.file_index).path.string();
request += escape_path(path.c_str(), path.length());
}
else
{
std::string path = m_path;
path += info.files().at(f.file_index).path.string();
path += info.orig_files().at(f.file_index).path.string();
request += escape_path(path.c_str(), path.length());
}
request += " HTTP/1.1\r\n";
@ -434,7 +434,7 @@ namespace libtorrent
int file_index = m_file_requests.front();
torrent_info const& info = t->torrent_file();
std::string path = info.files().at(file_index).path.string();
std::string path = info.orig_files().at(file_index).path.string();
path = escape_path(path.c_str(), path.length());
size_t i = location.rfind(path);
if (i == std::string::npos)
@ -528,7 +528,7 @@ namespace libtorrent
}
int file_index = m_file_requests.front();
peer_request in_range = info.files().map_file(file_index, range_start
peer_request in_range = info.orig_files().map_file(file_index, range_start
, int(range_end - range_start));
peer_request front_request = m_requests.front();