Index: util/file/file_io_win.cc |
diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc |
index adbe7a99efaa15498877220d67c38c40860f4170..6cd23978f69a6431eb8682f3e6feadeebe372619 100644 |
--- a/util/file/file_io_win.cc |
+++ b/util/file/file_io_win.cc |
@@ -102,13 +102,45 @@ FileHandle LoggingOpenFileForWrite(const base::FilePath& path, |
disposition = CREATE_NEW; |
break; |
} |
- HANDLE file = CreateFile(path.value().c_str(), GENERIC_WRITE, 0, nullptr, |
- disposition, FILE_ATTRIBUTE_NORMAL, nullptr); |
+ HANDLE file = CreateFile(path.value().c_str(), |
+ GENERIC_WRITE, |
+ FILE_SHARE_READ | FILE_SHARE_WRITE, |
+ nullptr, |
+ disposition, |
+ FILE_ATTRIBUTE_NORMAL, |
+ nullptr); |
PLOG_IF(ERROR, file == INVALID_HANDLE_VALUE) << "CreateFile " |
<< path.value().c_str(); |
return file; |
} |
+bool LoggingLockFile(FileHandle file, FileLocking locking) { |
+ DWORD flags = |
+ locking == FileLocking::kExclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0; |
Robert Sesek
2015/03/12 15:28:03
nit: () around condition
scottmg
2015/03/19 22:06:20
Done.
|
+ |
+ // Note that the `Offset` fields of overlapped indicate the start location for |
+ // locking (beginning of file in this case), and `hEvent` must be also be set |
+ // to 0. |
+ OVERLAPPED overlapped = {0}; |
+ if (!LockFileEx(file, flags, 0, MAXDWORD, MAXDWORD, &overlapped)) { |
+ PLOG(ERROR) << "LockFileEx"; |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+bool LoggingUnlockFile(FileHandle file) { |
+ // Note that the `Offset` fields of overlapped indicate the start location for |
+ // locking (beginning of file in this case), and `hEvent` must be also be set |
+ // to 0. |
+ OVERLAPPED overlapped = {0}; |
+ if (!UnlockFileEx(file, 0, MAXDWORD, MAXDWORD, &overlapped)) { |
+ PLOG(ERROR) << "LockFileEx"; |
+ return false; |
+ } |
+ return true; |
+} |
+ |
FileOffset LoggingSeekFile(FileHandle file, FileOffset offset, int whence) { |
DWORD method = 0; |
switch (whence) { |