1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-22 07:42:37 +00:00

refactor: remove unused TR_SYS_FILE_LOCK_UN (#7207)

This commit is contained in:
Charles Kerr 2024-10-29 00:14:53 -05:00 committed by GitHub
parent c36a62e171
commit c1047b8009
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 32 deletions

View file

@ -914,15 +914,14 @@ bool tr_sys_file_preallocate(tr_sys_file_t handle, uint64_t size, int flags, tr_
bool tr_sys_file_lock([[maybe_unused]] tr_sys_file_t handle, [[maybe_unused]] int operation, tr_error* error) bool tr_sys_file_lock([[maybe_unused]] tr_sys_file_t handle, [[maybe_unused]] int operation, tr_error* error)
{ {
TR_ASSERT(handle != TR_BAD_SYS_FILE); TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0); TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB)) == 0);
TR_ASSERT( TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) == 1);
!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) + !!(operation & TR_SYS_FILE_LOCK_UN) == 1);
#if defined(F_OFD_SETLK) #if defined(F_OFD_SETLK)
struct flock fl = {}; struct flock fl = {};
switch (operation & (TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_UN)) switch (operation & (TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX))
{ {
case TR_SYS_FILE_LOCK_SH: case TR_SYS_FILE_LOCK_SH:
fl.l_type = F_RDLCK; fl.l_type = F_RDLCK;
@ -932,10 +931,6 @@ bool tr_sys_file_lock([[maybe_unused]] tr_sys_file_t handle, [[maybe_unused]] in
fl.l_type = F_WRLCK; fl.l_type = F_WRLCK;
break; break;
case TR_SYS_FILE_LOCK_UN:
fl.l_type = F_UNLCK;
break;
default: default:
errno = EINVAL; errno = EINVAL;
break; break;
@ -963,8 +958,7 @@ bool tr_sys_file_lock([[maybe_unused]] tr_sys_file_t handle, [[maybe_unused]] in
int const native_operation = // int const native_operation = //
(((operation & TR_SYS_FILE_LOCK_SH) != 0) ? LOCK_SH : 0) | // (((operation & TR_SYS_FILE_LOCK_SH) != 0) ? LOCK_SH : 0) | //
(((operation & TR_SYS_FILE_LOCK_EX) != 0) ? LOCK_EX : 0) | // (((operation & TR_SYS_FILE_LOCK_EX) != 0) ? LOCK_EX : 0) | //
(((operation & TR_SYS_FILE_LOCK_NB) != 0) ? LOCK_NB : 0) | // (((operation & TR_SYS_FILE_LOCK_NB) != 0) ? LOCK_NB : 0);
(((operation & TR_SYS_FILE_LOCK_UN) != 0) ? LOCK_UN : 0);
auto result = std::optional<bool>{}; auto result = std::optional<bool>{};
while (!result) while (!result)

View file

@ -1054,15 +1054,11 @@ bool tr_sys_file_preallocate(tr_sys_file_t handle, uint64_t size, int flags, tr_
bool tr_sys_file_lock(tr_sys_file_t handle, int operation, tr_error* error) bool tr_sys_file_lock(tr_sys_file_t handle, int operation, tr_error* error)
{ {
TR_ASSERT(handle != TR_BAD_SYS_FILE); TR_ASSERT(handle != TR_BAD_SYS_FILE);
TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0); TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB)) == 0);
TR_ASSERT( TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) == 1);
!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) + !!(operation & TR_SYS_FILE_LOCK_UN) == 1);
bool ret = false;
auto overlapped = OVERLAPPED{}; auto overlapped = OVERLAPPED{};
if ((operation & TR_SYS_FILE_LOCK_UN) == 0)
{
DWORD native_flags = 0; DWORD native_flags = 0;
if ((operation & TR_SYS_FILE_LOCK_EX) != 0) if ((operation & TR_SYS_FILE_LOCK_EX) != 0)
@ -1075,12 +1071,7 @@ bool tr_sys_file_lock(tr_sys_file_t handle, int operation, tr_error* error)
native_flags |= LOCKFILE_FAIL_IMMEDIATELY; native_flags |= LOCKFILE_FAIL_IMMEDIATELY;
} }
ret = LockFileEx(handle, native_flags, 0, MAXDWORD, MAXDWORD, &overlapped) != FALSE; bool const ret = LockFileEx(handle, native_flags, 0, MAXDWORD, MAXDWORD, &overlapped) != FALSE;
}
else
{
ret = UnlockFileEx(handle, 0, MAXDWORD, MAXDWORD, &overlapped) != FALSE;
}
if (!ret) if (!ret)
{ {

View file

@ -59,8 +59,7 @@ enum tr_sys_file_lock_flags_t
{ {
TR_SYS_FILE_LOCK_SH = (1 << 0), TR_SYS_FILE_LOCK_SH = (1 << 0),
TR_SYS_FILE_LOCK_EX = (1 << 1), TR_SYS_FILE_LOCK_EX = (1 << 1),
TR_SYS_FILE_LOCK_NB = (1 << 2), TR_SYS_FILE_LOCK_NB = (1 << 2)
TR_SYS_FILE_LOCK_UN = (1 << 3)
}; };
enum tr_sys_path_get_info_flags_t enum tr_sys_path_get_info_flags_t