diff --git a/src/util/file_lock.cpp b/src/util/file_lock.cpp index 7d0ebc9296..561486bb11 100644 --- a/src/util/file_lock.cpp +++ b/src/util/file_lock.cpp @@ -96,9 +96,17 @@ file_lock::file_lock(char const * fname, bool exclusive): file_lock::~file_lock() { #if !defined(LEAN_EMSCRIPTEN) if (m_fd != -1) { +#if !defined(LEAN_WINDOWS) + /* On Windows, we cannot remove the file if it is locked. */ std::remove(m_fname.c_str()); +#endif flock(m_fd, LOCK_UN); close(m_fd); +#if defined(LEAN_WINDOWS) + /* On Windows, we (to) to remove the file after we released the lock. The operation will fail if another + process has a handle to it. However, this is better than always keeping all .lock files. */ + std::remove(m_fname.c_str()); +#endif } #endif }