[Box Backup-commit] COMMIT r1402 - box/chris/merge/lib/win32

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Mar 10 17:32:44 GMT 2007


Author: chris
Date: 2007-03-10 17:32:44 +0000 (Sat, 10 Mar 2007)
New Revision: 1402

Modified:
   box/chris/merge/lib/win32/emu.cpp
   box/chris/merge/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.

(refs #3, merges [1288])


Modified: box/chris/merge/lib/win32/emu.cpp
===================================================================
--- box/chris/merge/lib/win32/emu.cpp	2007-03-10 17:29:31 UTC (rev 1401)
+++ box/chris/merge/lib/win32/emu.cpp	2007-03-10 17:32:44 UTC (rev 1402)
@@ -541,31 +541,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;
 	}
 
@@ -573,7 +580,6 @@
 	if (flags & O_TEMPORARY)
 	{
 		winFlags  |= FILE_FLAG_DELETE_ON_CLOSE;
-		shareMode |= FILE_SHARE_DELETE;
 	}
 
 	HANDLE hdir = CreateFileW(pBuffer, 

Modified: box/chris/merge/lib/win32/emu.h
===================================================================
--- box/chris/merge/lib/win32/emu.h	2007-03-10 17:29:31 UTC (rev 1401)
+++ box/chris/merge/lib/win32/emu.h	2007-03-10 17:32:44 UTC (rev 1402)
@@ -290,6 +290,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




More information about the Boxbackup-commit mailing list