merged RC_1_1 into master

This commit is contained in:
Arvid Norberg 2018-07-07 18:21:01 +02:00
commit 3fede4b223
5 changed files with 52 additions and 32 deletions

View File

@ -210,9 +210,6 @@ namespace libtorrent {
handle_type m_file_handle;
open_mode_t m_open_mode{};
#if defined TORRENT_WINDOWS
static bool has_manage_volume_privs;
#endif
};
}

View File

@ -300,7 +300,7 @@ namespace {
disk_thread.set_settings(&sett);
int const piece_read_ahead = std::max(6, 16 * 1024 * 1024 / t.piece_length());
int const piece_read_ahead = std::max(12, 16 * 1024 * 1024 / t.piece_length());
hash_state st = { t, std::move(storage), disk_thread, piece_index_t(0), piece_index_t(0), f, ec };
for (piece_index_t i(0); i < piece_index_t(piece_read_ahead); ++i)

View File

@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_WINDOWS
#include <sys/uio.h> // for iovec
#else
#include <boost/scope_exit.hpp>
namespace {
struct iovec
{
@ -476,9 +477,6 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
#ifdef TORRENT_WINDOWS
bool get_manage_volume_privs();
// this needs to be run before CreateFile
bool file::has_manage_volume_privs = get_manage_volume_privs();
#endif
file::file() : m_file_handle(INVALID_HANDLE_VALUE)
@ -1047,11 +1045,9 @@ namespace {
#ifdef TORRENT_WINDOWS
bool get_manage_volume_privs()
{
using OpenProcessToken_t = BOOL (WINAPI*)(
HANDLE, DWORD, PHANDLE);
using OpenProcessToken_t = BOOL (WINAPI*)(HANDLE, DWORD, PHANDLE);
using LookupPrivilegeValue_t = BOOL (WINAPI*)(
LPCSTR, LPCSTR, PLUID);
using LookupPrivilegeValue_t = BOOL (WINAPI*)(LPCSTR, LPCSTR, PLUID);
using AdjustTokenPrivileges_t = BOOL (WINAPI*)(
HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
@ -1071,23 +1067,22 @@ namespace {
, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
return false;
BOOST_SCOPE_EXIT_ALL(&token) {
CloseHandle(token);
};
TOKEN_PRIVILEGES privs;
if (!LookupPrivilegeValue(nullptr, "SeManageVolumePrivilege"
, &privs.Privileges[0].Luid))
{
CloseHandle(token);
return false;
}
privs.PrivilegeCount = 1;
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bool ret = AdjustTokenPrivileges(token, FALSE, &privs, 0, nullptr, nullptr)
return AdjustTokenPrivileges(token, FALSE, &privs, 0, nullptr, nullptr)
&& GetLastError() == ERROR_SUCCESS;
CloseHandle(token);
return ret;
}
void set_file_valid_data(HANDLE f, std::int64_t size)
@ -1098,9 +1093,14 @@ namespace {
if (SetFileValidData == nullptr) return;
// we don't necessarily expect to have enough
// privilege to do this, so ignore errors.
SetFileValidData(f, size);
static bool const has_manage_volume_privs = get_manage_volume_privs();
if (has_manage_volume_privs)
{
// we don't necessarily expect to have enough
// privilege to do this, so ignore errors.
SetFileValidData(f, size);
}
}
#endif

View File

@ -2289,9 +2289,9 @@ bool is_downloading_state(int const st)
int num_outstanding = settings().get_int(settings_pack::checking_mem_usage) * block_size()
/ m_torrent_file->piece_length();
// if we only keep a single read operation in-flight at a time, we suffer
// significant performance degradation. Always keep at least two jobs
// significant performance degradation. Always keep at least 4 jobs
// outstanding per hasher thread
int const min_outstanding = 2
int const min_outstanding = 4
* std::max(1, settings().get_int(settings_pack::aio_threads)
/ disk_io_thread::hasher_thread_divisor);
if (num_outstanding < min_outstanding) num_outstanding = min_outstanding;
@ -5024,10 +5024,7 @@ bool is_downloading_state(int const st)
{
aux::vector<download_priority_t, file_index_t> files(input.begin(), input.end());
if (fs)
{
files.resize(fs->num_files(), default_priority);
}
if (fs) files.resize(fs->num_files(), default_priority);
for (file_index_t i : index_range<file_index_t>{file_index_t{}, files.end_index()})
{
@ -5072,7 +5069,8 @@ bool is_downloading_state(int const st)
if (is_seed()) return;
auto new_priority = fix_priorities(files, valid_metadata() ? &m_torrent_file->files() : nullptr);
auto new_priority = fix_priorities(files
, valid_metadata() ? &m_torrent_file->files() : nullptr);
// storage may be NULL during shutdown
if (m_storage)

View File

@ -84,7 +84,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false)
cleanup();
settings_pack pack = sett;
lt::settings_pack pack = sett;
// we need a short reconnect time since we
// finish the torrent and then restart it
@ -411,10 +411,36 @@ TORRENT_TEST(priority_deprecated)
// test to set piece and file priority on a torrent that doesn't have metadata
// yet
TORRENT_TEST(no_metadata_prioritize_files)
{
lt::session ses(settings());
add_torrent_params addp;
addp.flags &= ~torrent_flags::paused;
addp.flags &= ~torrent_flags::auto_managed;
addp.info_hash = sha1_hash("abababababababababab");
addp.save_path = ".";
torrent_handle h = ses.add_torrent(addp);
std::vector<lt::download_priority_t> prios(3);
prios[0] = lt::dont_download;
h.prioritize_files(prios);
// TODO 2: this should wait for an alert instead of just sleeping
std::this_thread::sleep_for(lt::milliseconds(100));
TEST_CHECK(h.get_file_priorities() == prios);
prios[0] = lt::low_priority;
h.prioritize_files(prios);
std::this_thread::sleep_for(lt::milliseconds(100));
TEST_CHECK(h.get_file_priorities() == prios);
ses.remove_torrent(h);
}
TORRENT_TEST(no_metadata_file_prio)
{
settings_pack pack = settings();
lt::session ses(pack);
lt::session ses(settings());
add_torrent_params addp;
addp.flags &= ~torrent_flags::paused;
@ -436,8 +462,7 @@ TORRENT_TEST(no_metadata_file_prio)
TORRENT_TEST(no_metadata_piece_prio)
{
settings_pack pack = settings();
lt::session ses(pack);
lt::session ses(settings());
add_torrent_params addp;
addp.flags &= ~torrent_flags::paused;