diff --git a/libtorrent/include/libtorrent/session_settings.hpp b/libtorrent/include/libtorrent/session_settings.hpp index 3d48fbbba..e71efc7e3 100644 --- a/libtorrent/include/libtorrent/session_settings.hpp +++ b/libtorrent/include/libtorrent/session_settings.hpp @@ -142,6 +142,7 @@ namespace libtorrent , max_peerlist_size(8000) , min_announce_interval(5 * 60) , prioritize_partial_pieces(false) + , auto_manage_startup(120) {} // this is the user agent that will be sent to the tracker @@ -441,6 +442,14 @@ namespace libtorrent // if true, partial pieces are picked before pieces // that are more rare bool prioritize_partial_pieces; + + // the number of seconds a torrent is considered + // active after it was started, regardless of + // upload and download speed. This is so that + // newly started torrents are not considered + // inactive until they have a fair chance to + // start downloading. + int auto_manage_startup; }; #ifndef TORRENT_DISABLE_DHT diff --git a/libtorrent/include/libtorrent/torrent.hpp b/libtorrent/include/libtorrent/torrent.hpp index 356e2feff..ea5a91fbb 100644 --- a/libtorrent/include/libtorrent/torrent.hpp +++ b/libtorrent/include/libtorrent/torrent.hpp @@ -217,6 +217,7 @@ namespace libtorrent void pause(); void resume(); + ptime started() const { return m_started; } void do_pause(); void do_resume(); diff --git a/libtorrent/include/libtorrent/torrent_info.hpp b/libtorrent/include/libtorrent/torrent_info.hpp index 51cca20a5..d3c74803e 100644 --- a/libtorrent/include/libtorrent/torrent_info.hpp +++ b/libtorrent/include/libtorrent/torrent_info.hpp @@ -93,6 +93,7 @@ namespace libtorrent ~torrent_info(); file_storage const& files() const { return m_files; } + file_storage& files() { return m_files; } void add_tracker(std::string const& url, int tier = 0); std::vector const& trackers() const { return m_urls; } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index e633a1a1a..f414a8e58 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -1283,7 +1283,8 @@ namespace aux { { return !(s.dont_count_slow_torrents && t->statistics().upload_payload_rate() == 0.f - && t->statistics().download_payload_rate() == 0.f); + && t->statistics().download_payload_rate() == 0.f + && time_now() - t->started() > seconds(s.auto_manage_startup)); } } diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 8466109e3..82ed21ffc 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -53,6 +53,9 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#if BOOST_VERSION >= 103500 +#include +#endif #ifdef _MSC_VER #pragma warning(pop) @@ -581,7 +584,11 @@ namespace libtorrent try { #endif - rename(old_path, new_path); + // if old path doesn't exist, just rename the file + // in our file_storage, so that when it is created + // it will get the new name + create_directories(new_path.branch_path()); + if (exists(old_path)) rename(old_path, new_path); /* error_code ec; rename(old_path, new_path, ec); @@ -596,6 +603,13 @@ namespace libtorrent m_mapped_files->rename_file(index, new_filename); #ifndef BOOST_NO_EXCEPTIONS } +#if BOOST_VERSION >= 103500 + catch (boost::system::system_error& e) + { + set_error(old_name, e.code()); + return true; + } +#endif catch (std::exception& e) { set_error(old_name, error_code(errno, get_posix_category())); @@ -726,15 +740,6 @@ namespace libtorrent m_file_priority[i] = file_priority->list_int_value_at(i, 1); } - lazy_entry const* mapped_files = rd.dict_find_list("mapped_files"); - if (mapped_files && mapped_files->list_size() == m_files.num_files()) - { - if (!m_mapped_files) - { m_mapped_files.reset(new file_storage(m_files)); } - for (int i = 0; i < m_files.num_files(); ++i) - m_mapped_files->rename_file(i, mapped_files->list_string_value_at(i)); - } - std::vector > file_sizes; lazy_entry const* file_sizes_ent = rd.dict_find_list("file sizes"); if (file_sizes_ent == 0) diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 40dbb87c5..479459510 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1659,6 +1659,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); } else { @@ -2549,6 +2550,17 @@ namespace libtorrent < boost::bind(&announce_entry::tier, _2)); } + lazy_entry const* mapped_files = rd.dict_find_list("mapped_files"); + if (mapped_files && mapped_files->list_size() == m_torrent_file->num_files()) + { + for (int i = 0; i < m_torrent_file->num_files(); ++i) + { + 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); + } + } + lazy_entry const* url_list = rd.dict_find_list("url-list"); if (url_list) {