diff options
author | Andrew Stitcher <astitcher@apache.org> | 2009-12-15 23:02:29 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2009-12-15 23:02:29 +0000 |
commit | 3e14068a726098d299ea07918f3910438093b3c2 (patch) | |
tree | 28ae46220e313136eb962a0890b18bf2f576d227 | |
parent | d6fe85cc830cd6f8647620e82159090d42f9788d (diff) | |
download | qpid-python-3e14068a726098d299ea07918f3910438093b3c2.tar.gz |
QPID-2281: LockFile class now actually locks the file!
[before it just opened the file without locking it]
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@891061 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | cpp/src/qpid/sys/windows/LockFile.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/cpp/src/qpid/sys/windows/LockFile.cpp b/cpp/src/qpid/sys/windows/LockFile.cpp index e9fe01ca72..048c2d5b18 100755 --- a/cpp/src/qpid/sys/windows/LockFile.cpp +++ b/cpp/src/qpid/sys/windows/LockFile.cpp @@ -36,7 +36,7 @@ public: LockFile::LockFile(const std::string& path_, bool create) : path(path_), created(create) { - HANDLE h = CreateFile(path.c_str(), + HANDLE h = ::CreateFile(path.c_str(), create ? (GENERIC_READ|GENERIC_WRITE) : GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, /* Default security */ @@ -44,14 +44,19 @@ LockFile::LockFile(const std::string& path_, bool create) FILE_FLAG_DELETE_ON_CLOSE, /* Delete file when closed */ NULL); if (h == INVALID_HANDLE_VALUE) - throw qpid::Exception(path + qpid::sys::strError(GetLastError())); + throw qpid::Exception(path + ": " + qpid::sys::strError(GetLastError())); + + // Lock up to 4Gb + if (!::LockFile(h, 0, 0, 0xffffffff, 0)) + throw qpid::Exception(path + ": " + qpid::sys::strError(GetLastError())); impl.reset(new LockFilePrivate(h)); } LockFile::~LockFile() { if (impl) { if (impl->fd != INVALID_HANDLE_VALUE) { - CloseHandle(impl->fd); + ::UnlockFile(impl->fd, 0, 0, 0xffffffff, 0); + ::CloseHandle(impl->fd); } } } |