diff --git a/libtorrent/include/libtorrent/torrent_info.hpp b/libtorrent/include/libtorrent/torrent_info.hpp index d3c74803e..c71624ce8 100644 --- a/libtorrent/include/libtorrent/torrent_info.hpp +++ b/libtorrent/include/libtorrent/torrent_info.hpp @@ -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 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 m_orig_files; + // the urls to the trackers std::vector m_urls; std::vector m_url_seeds; diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index edccf8831..a4403200b 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -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; diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 4ee05d59d..dffcf18bc 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1674,7 +1674,7 @@ namespace libtorrent { if (alerts().should_post()) 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); } } diff --git a/libtorrent/src/torrent_info.cpp b/libtorrent/src/torrent_info.cpp index bcfa67a35..e7f173d6c 100755 --- a/libtorrent/src/torrent_info.cpp +++ b/libtorrent/src/torrent_info.cpp @@ -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); diff --git a/libtorrent/src/web_peer_connection.cpp b/libtorrent/src/web_peer_connection.cpp index fd8a30346..b856d0ec4 100755 --- a/libtorrent/src/web_peer_connection.cpp +++ b/libtorrent/src/web_peer_connection.cpp @@ -243,7 +243,7 @@ namespace libtorrent } else { - std::vector files = info.files().map_block(r.piece, r.start + std::vector files = info.orig_files().map_block(r.piece, r.start , r.length); for (std::vector::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();