From db79efcb7b75f50d4314bfb3af86e38ea947358b Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Thu, 13 Mar 2025 16:37:18 +0100 Subject: [PATCH] fix: Fix log file locking on Windows Fixes #1575. (cherry picked from commit 1581d9a3c9f7894334aa5e0745fc4d3d3bbdacd3) --- src/ccache/util/filelock.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ccache/util/filelock.cpp b/src/ccache/util/filelock.cpp index e6874966..379afa5e 100644 --- a/src/ccache/util/filelock.cpp +++ b/src/ccache/util/filelock.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Joel Rosdahl and other contributors +// Copyright (C) 2024-2025 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -64,7 +64,11 @@ FileLock::acquire() if (handle == INVALID_HANDLE_VALUE) { return false; } - m_acquired = LockFile(handle, 0, 0, MAXDWORD, MAXDWORD) != 0; + OVERLAPPED overlapped{}; + m_acquired = + LockFileEx( + handle, LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, MAXDWORD, &overlapped) + != 0; #else struct flock lock; memset(&lock, 0, sizeof(lock)); -- 2.47.2