From 7e0612306fea16462a59414da3f615af1daf86fd Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Tue, 20 Dec 2016 14:00:50 -0800 Subject: [PATCH] fix(util/file_lock): issue on Windows --- src/util/file_lock.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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 }