fix(util/file_lock): issue on Windows

This commit is contained in:
Leonardo de Moura 2016-12-20 14:00:50 -08:00
parent a358ea32ac
commit 7e0612306f

View file

@ -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
}