[Box Backup-commit] COMMIT r1288 - box/chris/general/lib/win32
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Wed, 14 Feb 2007 23:17:40 +0000
Author: chris
Date: 2007-02-14 23:17:40 +0000 (Wed, 14 Feb 2007)
New Revision: 1288
Modified:
box/chris/general/lib/win32/emu.cpp
box/chris/general/lib/win32/emu.h
Log:
Fix handling of O_EXCL to behave just like Unix, not abused to lock files.
Add a new constant which specifies that files are to be locked open.
Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp 2007-02-14 23:16:49 UTC (rev 1287)
+++ box/chris/general/lib/win32/emu.cpp 2007-02-14 23:17:40 UTC (rev 1288)
@@ -525,31 +525,38 @@
// flags could be O_WRONLY | O_CREAT | O_RDONLY
DWORD createDisposition = OPEN_EXISTING;
- DWORD shareMode = FILE_SHARE_READ;
- DWORD accessRights = FILE_READ_ATTRIBUTES | FILE_LIST_DIRECTORY | FILE_READ_EA;
+ DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE
+ | FILE_SHARE_DELETE;
+ DWORD accessRights = FILE_READ_ATTRIBUTES | FILE_LIST_DIRECTORY
+ | FILE_READ_EA;
if (flags & O_WRONLY)
{
accessRights = FILE_WRITE_DATA;
- shareMode = FILE_SHARE_WRITE;
}
else if (flags & O_RDWR)
{
accessRights |= FILE_WRITE_ATTRIBUTES
| FILE_WRITE_DATA | FILE_WRITE_EA;
- shareMode |= FILE_SHARE_WRITE;
}
if (flags & O_CREAT)
{
createDisposition = OPEN_ALWAYS;
}
+
if (flags & O_TRUNC)
{
createDisposition = CREATE_ALWAYS;
}
- if (flags & O_EXCL)
+
+ if ((flags & O_CREAT) && (flags & O_EXCL))
{
+ createDisposition = CREATE_NEW;
+ }
+
+ if (flags & O_LOCK)
+ {
shareMode = 0;
}
@@ -557,7 +564,6 @@
if (flags & O_TEMPORARY)
{
winFlags |= FILE_FLAG_DELETE_ON_CLOSE;
- shareMode |= FILE_SHARE_DELETE;
}
HANDLE hdir = CreateFileW(pBuffer,
Modified: box/chris/general/lib/win32/emu.h
===================================================================
--- box/chris/general/lib/win32/emu.h 2007-02-14 23:16:49 UTC (rev 1287)
+++ box/chris/general/lib/win32/emu.h 2007-02-14 23:17:40 UTC (rev 1288)
@@ -209,6 +209,9 @@
struct dirent *readdir(DIR *dp);
int closedir(DIR *dp);
+// local constant to open file exclusively without shared access
+#define O_LOCK 0x10000
+
HANDLE openfile(const char *filename, int flags, int mode);
#define LOG_INFO 6