From 4cef1814b074c215b21d1cea6051c6e971552280 Mon Sep 17 00:00:00 2001 From: sledgehammer_999 Date: Mon, 28 May 2018 01:35:16 +0300 Subject: [PATCH 1/3] Add 1.1.7 release in the ChangeLog --- ChangeLog | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a8258a171..0ea270d21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,16 @@ * set the hidden attribute when creating the part file + * fix tracker announces reporting more data downloaded than the size of the torrent * fix recent regression with force_proxy setting + +1.1.7 release + * don't perform DNS lookups for the DHT bootstrap unless DHT is enabled * fix issue where setting file/piece priority would stop checking * expose post_dht_stats() to python binding * fix backwards compatibility to downloads without partfiles * improve part-file related error messages * fix reporting &redundant= in tracker announces - * fix tracker announces reporting more data downloaded than the size of the torrent * fix tie-break in duplicate peer connection disconnect logic * fix issue with SSL tracker connections left in CLOSE_WAIT state * defer truncating existing files until the first time we write to them From 396c5dd3af39a45bf0e9edb37b9754f040de808d Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 22 Jul 2017 19:44:44 -0700 Subject: [PATCH 2/3] remove use of deprecated function readdir_r Ports 140b8ace onto RC_1_1 branch --- examples/client_test.cpp | 9 +++------ include/libtorrent/file.hpp | 7 ++----- src/file.cpp | 22 ++++++++++------------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index bb486806f..db53a4524 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -762,13 +762,10 @@ std::vector list_dir(std::string path return ret; } - struct dirent de; - dirent* dummy; - while (readdir_r(handle, &de, &dummy) == 0) + struct dirent* de; + while ((de = readdir(handle))) { - if (dummy == 0) break; - - std::string p = de.d_name; + std::string p = de->d_name; if (filter_fun(p)) ret.push_back(p); } diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index e597ce1c6..486d4f6ca 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -193,11 +193,8 @@ namespace libtorrent #endif #else DIR* m_handle; - // the dirent struct contains a zero-sized - // array at the end, it will end up referring - // to the m_name field - struct dirent m_dirent; - char m_name[TORRENT_MAX_PATH + 1]; // +1 to make room for null + ino_t m_inode; + std::string m_name; #endif bool m_done; }; diff --git a/src/file.cpp b/src/file.cpp index 0db8f56eb..1b3a88150 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1185,9 +1185,6 @@ namespace libtorrent } #else - memset(&m_dirent, 0, sizeof(dirent)); - m_name[0] = 0; - // the path passed to opendir() may not // end with a / std::string p = path; @@ -1219,11 +1216,7 @@ namespace libtorrent boost::uint64_t directory::inode() const { -#ifdef TORRENT_WINDOWS return m_inode; -#else - return m_dirent.d_ino; -#endif } std::string directory::file() const @@ -1235,7 +1228,7 @@ namespace libtorrent return convert_from_native(m_fd.cFileName); #endif #else - return convert_from_native(m_dirent.d_name); + return convert_from_native(m_name); #endif } @@ -1257,13 +1250,18 @@ namespace libtorrent } ++m_inode; #else - dirent* dummy; - if (readdir_r(m_handle, &m_dirent, &dummy) != 0) + struct dirent* de; + errno = 0; + if ((de = ::readdir(m_handle))) { - ec.assign(errno, system_category()); + m_inode = de->d_ino; + m_name = de->d_name; + } + else + { + if (errno) ec.assign(errno, system_category()); m_done = true; } - if (dummy == 0) m_done = true; #endif } From c55bc7dd420f5f79b571e85d0984049a6fa28307 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 23 May 2018 12:09:22 +0200 Subject: [PATCH 3/3] improve error handling of failing to change file priority --- ChangeLog | 2 ++ include/libtorrent/storage.hpp | 8 ++++---- include/libtorrent/torrent.hpp | 2 +- src/disk_io_thread.cpp | 3 +-- src/storage.cpp | 15 +++++++++++++-- src/torrent.cpp | 21 +++++++++++++++++---- test/test_block_cache.cpp | 2 +- test/test_transfer.cpp | 6 +++--- 8 files changed, 42 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ea270d21..d6ec9ef20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ + * improve error handling of failing to change file priority + The API for custom storage implementations was altered * set the hidden attribute when creating the part file * fix tracker announces reporting more data downloaded than the size of the torrent * fix recent regression with force_proxy setting diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index a8f12846e..25ccd8697 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -276,7 +276,7 @@ namespace libtorrent // change the priorities of files. This is a fenced job and is // guaranteed to be the only running function on this storage // when called - virtual void set_file_priority(std::vector const& prio + virtual void set_file_priority(std::vector& prio , storage_error& ec) = 0; // This function should move all the files belonging to the storage to @@ -427,7 +427,7 @@ namespace libtorrent void finalize_file(int file, storage_error& ec) TORRENT_OVERRIDE; #endif virtual bool has_any_file(storage_error& ec) TORRENT_OVERRIDE; - virtual void set_file_priority(std::vector const& prio + virtual void set_file_priority(std::vector& prio , storage_error& ec) TORRENT_OVERRIDE; virtual void rename_file(int index, std::string const& new_filename , storage_error& ec) TORRENT_OVERRIDE; @@ -524,7 +524,7 @@ namespace libtorrent { public: virtual bool has_any_file(storage_error&) TORRENT_OVERRIDE { return false; } - virtual void set_file_priority(std::vector const& + virtual void set_file_priority(std::vector& , storage_error&) TORRENT_OVERRIDE {} virtual void rename_file(int, std::string const&, storage_error&) TORRENT_OVERRIDE {} virtual void release_files(storage_error&) TORRENT_OVERRIDE {} @@ -555,7 +555,7 @@ namespace libtorrent , int piece, int offset, int flags, storage_error& ec) TORRENT_OVERRIDE; virtual bool has_any_file(storage_error&) TORRENT_OVERRIDE { return false; } - virtual void set_file_priority(std::vector const& /* prio */ + virtual void set_file_priority(std::vector& /* prio */ , storage_error&) TORRENT_OVERRIDE {} virtual int move_storage(std::string const& /* save_path */ , int /* flags */, storage_error&) TORRENT_OVERRIDE { return 0; } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index ac9a8dbe1..778a9886e 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -544,7 +544,7 @@ namespace libtorrent void set_file_priority(int index, int priority); int file_priority(int index) const; - void on_file_priority(); + void on_file_priority(disk_io_job const* j); void prioritize_files(std::vector const& files); void file_priorities(std::vector*) const; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index deb02a446..5a092bc82 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2991,8 +2991,7 @@ namespace libtorrent int disk_io_thread::do_file_priority(disk_io_job* j, jobqueue_t& /* completed_jobs */ ) { - boost::scoped_ptr > p(j->buffer.priorities); - j->storage->get_storage_impl()->set_file_priority(*p, j->error); + j->storage->get_storage_impl()->set_file_priority(*j->buffer.priorities, j->error); return 0; } diff --git a/src/storage.cpp b/src/storage.cpp index 11261b3d6..a2ddef25d 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -436,7 +436,7 @@ namespace libtorrent , m_files.num_pieces(), m_files.piece_length())); } - void default_storage::set_file_priority(std::vector const& prio, storage_error& ec) + void default_storage::set_file_priority(std::vector& prio, storage_error& ec) { // extend our file priorities in case it's truncated // the default assumed priority is 4 (the default) @@ -459,6 +459,7 @@ namespace libtorrent { ec.file = i; ec.operation = storage_error::open; + prio = m_file_priority; return; } @@ -469,6 +470,7 @@ namespace libtorrent { ec.file = i; ec.operation = storage_error::partfile_write; + prio = m_file_priority; return; } } @@ -485,7 +487,13 @@ namespace libtorrent file_handle f = open_file(i, file::read_only, ec); if (ec.ec != boost::system::errc::no_such_file_or_directory) { - if (ec) return; + if (ec) + { + ec.file = i; + ec.operation = storage_error::open; + prio = m_file_priority; + return; + } need_partfile(); @@ -494,6 +502,7 @@ namespace libtorrent { ec.file = i; ec.operation = storage_error::partfile_read; + prio = m_file_priority; return; } // remove the file @@ -503,6 +512,8 @@ namespace libtorrent { ec.file = i; ec.operation = storage_error::remove; + prio = m_file_priority; + return; } } */ diff --git a/src/torrent.cpp b/src/torrent.cpp index 99fcc5781..2f7e02811 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5658,9 +5658,22 @@ namespace { } } - void torrent::on_file_priority() + void torrent::on_file_priority(disk_io_job const* j) { dec_refcount("file_priority"); + boost::scoped_ptr > p(j->buffer.priorities); + if (m_file_priority == *p) return; + + // in this case, some file priorities failed to get set + m_file_priority = *p; + update_piece_priorities(); + + if (alerts().should_post()) + alerts().emplace_alert(j->error.ec + , resolve_filename(j->error.file), j->error.operation_str(), get_handle()); + + set_error(j->error.ec, j->error.file); + pause(); } void torrent::prioritize_files(std::vector const& files) @@ -5699,7 +5712,7 @@ namespace { { inc_refcount("file_priority"); m_ses.disk_thread().async_set_file_priority(m_storage.get() - , m_file_priority, boost::bind(&torrent::on_file_priority, shared_from_this())); + , m_file_priority, boost::bind(&torrent::on_file_priority, shared_from_this(), _1)); } update_piece_priorities(); @@ -5738,7 +5751,7 @@ namespace { { inc_refcount("file_priority"); m_ses.disk_thread().async_set_file_priority(m_storage.get() - , m_file_priority, boost::bind(&torrent::on_file_priority, shared_from_this())); + , m_file_priority, boost::bind(&torrent::on_file_priority, shared_from_this(), _1)); } update_piece_priorities(); } @@ -7145,7 +7158,7 @@ namespace { { inc_refcount("file_priority"); m_ses.disk_thread().async_set_file_priority(m_storage.get() - , m_file_priority, boost::bind(&torrent::on_file_priority, shared_from_this())); + , m_file_priority, boost::bind(&torrent::on_file_priority, shared_from_this(), _1)); } update_piece_priorities(); diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index 5a6eab340..0d1621e78 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -61,7 +61,7 @@ struct test_storage_impl : storage_interface } virtual bool has_any_file(storage_error& ec) { return false; } - virtual void set_file_priority(std::vector const& prio + virtual void set_file_priority(std::vector& prio , storage_error& ec) {} virtual int move_storage(std::string const& save_path, int flags , storage_error& ec) { return 0; } diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index d1cef7c9c..41e1fedd5 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -78,8 +78,8 @@ struct test_storage : default_storage , m_limit(16 * 1024 * 2) {} - virtual void set_file_priority(std::vector const& p - , storage_error& ec) {} + virtual void set_file_priority(std::vector& p + , storage_error& ec) TORRENT_OVERRIDE {} void set_limit(int lim) { @@ -93,7 +93,7 @@ struct test_storage : default_storage , int piece_index , int offset , int flags - , storage_error& se) + , storage_error& se) TORRENT_OVERRIDE { mutex::scoped_lock l(m_mutex); if (m_written >= m_limit)