merged RC_1_1 into master
This commit is contained in:
commit
59343f4f95
|
@ -87,6 +87,8 @@
|
||||||
* resume data no longer has timestamps of files
|
* resume data no longer has timestamps of files
|
||||||
* require C++11 to build libtorrent
|
* require C++11 to build libtorrent
|
||||||
|
|
||||||
|
* fix potential deadlock on Windows, caused by performing restricted
|
||||||
|
tasks from within DllMain
|
||||||
* fix issue when subsequent file priority updates cause torrent to stop
|
* fix issue when subsequent file priority updates cause torrent to stop
|
||||||
|
|
||||||
1.1.8 release
|
1.1.8 release
|
||||||
|
|
37
src/file.cpp
37
src/file.cpp
|
@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||||
|
#include <mutex> // for call_once
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
@ -317,7 +318,7 @@ done:
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
# else
|
# else
|
||||||
# undef _BSD_SOURCE
|
# undef _BSD_SOURCE
|
||||||
# define _BSD_SOURCE // deprecated since glibc 2.20
|
# define _BSD_SOURCE // deprecated since glibc 2.20
|
||||||
|
@ -476,7 +477,7 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
|
||||||
|
|
||||||
|
|
||||||
#ifdef TORRENT_WINDOWS
|
#ifdef TORRENT_WINDOWS
|
||||||
bool get_manage_volume_privs();
|
void acquire_manage_volume_privs();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
file::file() : m_file_handle(INVALID_HANDLE_VALUE)
|
file::file() : m_file_handle(INVALID_HANDLE_VALUE)
|
||||||
|
@ -539,6 +540,14 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
|
||||||
| FILE_FLAG_OVERLAPPED
|
| FILE_FLAG_OVERLAPPED
|
||||||
| ((mode & open_mode::no_cache) ? FILE_FLAG_WRITE_THROUGH : 0);
|
| ((mode & open_mode::no_cache) ? FILE_FLAG_WRITE_THROUGH : 0);
|
||||||
|
|
||||||
|
if (!(mode & open_mode::sparse))
|
||||||
|
{
|
||||||
|
// Enable privilege required by SetFileValidData()
|
||||||
|
// https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilevaliddata
|
||||||
|
static std::once_flag flag;
|
||||||
|
std::call_once(flag, acquire_manage_volume_privs);
|
||||||
|
}
|
||||||
|
|
||||||
handle_type handle = CreateFileW(file_path.c_str(), m.rw_mode
|
handle_type handle = CreateFileW(file_path.c_str(), m.rw_mode
|
||||||
, FILE_SHARE_READ | FILE_SHARE_WRITE
|
, FILE_SHARE_READ | FILE_SHARE_WRITE
|
||||||
, 0, m.create_mode, flags, 0);
|
, 0, m.create_mode, flags, 0);
|
||||||
|
@ -1043,7 +1052,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_WINDOWS
|
#ifdef TORRENT_WINDOWS
|
||||||
bool get_manage_volume_privs()
|
void acquire_manage_volume_privs()
|
||||||
{
|
{
|
||||||
using OpenProcessToken_t = BOOL (WINAPI*)(HANDLE, DWORD, PHANDLE);
|
using OpenProcessToken_t = BOOL (WINAPI*)(HANDLE, DWORD, PHANDLE);
|
||||||
|
|
||||||
|
@ -1059,30 +1068,34 @@ namespace {
|
||||||
auto AdjustTokenPrivileges =
|
auto AdjustTokenPrivileges =
|
||||||
aux::get_library_procedure<aux::advapi32, AdjustTokenPrivileges_t>("AdjustTokenPrivileges");
|
aux::get_library_procedure<aux::advapi32, AdjustTokenPrivileges_t>("AdjustTokenPrivileges");
|
||||||
|
|
||||||
if (OpenProcessToken == nullptr || LookupPrivilegeValue == nullptr || AdjustTokenPrivileges == nullptr) return false;
|
if (OpenProcessToken == nullptr
|
||||||
|
|| LookupPrivilegeValue == nullptr
|
||||||
|
|| AdjustTokenPrivileges == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HANDLE token;
|
HANDLE token;
|
||||||
if (!OpenProcessToken(GetCurrentProcess()
|
if (!OpenProcessToken(GetCurrentProcess()
|
||||||
, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
|
, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
BOOST_SCOPE_EXIT_ALL(&token) {
|
BOOST_SCOPE_EXIT_ALL(&token) {
|
||||||
CloseHandle(token);
|
CloseHandle(token);
|
||||||
};
|
};
|
||||||
|
|
||||||
TOKEN_PRIVILEGES privs;
|
TOKEN_PRIVILEGES privs{};
|
||||||
if (!LookupPrivilegeValue(nullptr, "SeManageVolumePrivilege"
|
if (!LookupPrivilegeValue(nullptr, "SeManageVolumePrivilege"
|
||||||
, &privs.Privileges[0].Luid))
|
, &privs.Privileges[0].Luid))
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
privs.PrivilegeCount = 1;
|
privs.PrivilegeCount = 1;
|
||||||
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||||
|
|
||||||
return AdjustTokenPrivileges(token, FALSE, &privs, 0, nullptr, nullptr)
|
AdjustTokenPrivileges(token, FALSE, &privs, 0, nullptr, nullptr);
|
||||||
&& GetLastError() == ERROR_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_file_valid_data(HANDLE f, std::int64_t size)
|
void set_file_valid_data(HANDLE f, std::int64_t size)
|
||||||
|
@ -1091,11 +1104,7 @@ namespace {
|
||||||
auto SetFileValidData =
|
auto SetFileValidData =
|
||||||
aux::get_library_procedure<aux::kernel32, SetFileValidData_t>("SetFileValidData");
|
aux::get_library_procedure<aux::kernel32, SetFileValidData_t>("SetFileValidData");
|
||||||
|
|
||||||
if (SetFileValidData == nullptr) return;
|
if (SetFileValidData)
|
||||||
|
|
||||||
static bool const has_manage_volume_privs = get_manage_volume_privs();
|
|
||||||
|
|
||||||
if (has_manage_volume_privs)
|
|
||||||
{
|
{
|
||||||
// we don't necessarily expect to have enough
|
// we don't necessarily expect to have enough
|
||||||
// privilege to do this, so ignore errors.
|
// privilege to do this, so ignore errors.
|
||||||
|
|
Loading…
Reference in New Issue