From e9ea5f21a90cca3623115a3c901d033b81f97eb6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 13 Dec 2015 23:46:22 +0000 Subject: Fix Windows file locking to work with MSVC --- lib/common/NamedLock.cpp | 3 +++ lib/win32/emu.cpp | 2 +- lib/win32/emu.h | 2 +- test/bbackupd/testbbackupd.cpp | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp index 8cacf065..e440408e 100644 --- a/lib/common/NamedLock.cpp +++ b/lib/common/NamedLock.cpp @@ -82,6 +82,9 @@ bool NamedLock::TryAndGetLock(const std::string& rFilename, int mode) #if HAVE_DECL_O_EXLOCK flags |= O_NONBLOCK | O_EXLOCK; BOX_TRACE("Trying to create lockfile " << rFilename << " using O_EXLOCK"); +#elif defined BOX_OPEN_LOCK + flags |= BOX_OPEN_LOCK; + BOX_TRACE("Trying to create lockfile " << rFilename << " using BOX_OPEN_LOCK"); #elif !HAVE_DECL_F_SETLK && !defined HAVE_FLOCK // We have no other way to get a lock, so all we can do is fail if // the file already exists, and take the risk of stale locks. diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp index 658bfbbc..65c12b09 100644 --- a/lib/win32/emu.cpp +++ b/lib/win32/emu.cpp @@ -613,7 +613,7 @@ HANDLE openfile(const char *pFileName, int flags, int mode) createDisposition = CREATE_NEW; } - if (flags & O_LOCK) + if (flags & BOX_OPEN_LOCK) { shareMode = 0; } diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 8014316a..80c1d5d8 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -224,7 +224,7 @@ struct dirent *readdir(DIR *dp); int closedir(DIR *dp); // local constant to open file exclusively without shared access -#define O_LOCK 0x10000 +#define BOX_OPEN_LOCK 0x10000 extern DWORD winerrno; /* used to report errors from openfile() */ HANDLE openfile(const char *filename, int flags, int mode); diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index a9855250..f99ffcb4 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -3899,7 +3899,7 @@ bool test_locked_file_behaviour() // and the appropriate error is reported. HANDLE handle = openfile("testfiles/TestDir1/f1.dat", - O_LOCK, 0); + BOX_OPEN_LOCK, 0); TEST_THAT_OR(handle != INVALID_HANDLE_VALUE, FAIL); { @@ -3928,7 +3928,7 @@ bool test_locked_file_behaviour() // open the file again, compare and check that compare // reports the correct error message (and finishes) handle = openfile("testfiles/TestDir1/f1.dat", - O_LOCK, 0); + BOX_OPEN_LOCK, 0); TEST_THAT_OR(handle != INVALID_HANDLE_VALUE, FAIL); TEST_COMPARE(Compare_Error); -- cgit v1.2.3