about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-03-20 13:59:07 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-03-21 09:26:34 -0700
commit988664ac8a9ae3f53341afd5a60d5e11d3f0ba7e (patch)
treeb12922a555cfc729323edff7a6e984418c06b8d1
parent7334c11b4b196e39da2418a239e2ff916896fa19 (diff)
downloadrust-988664ac8a9ae3f53341afd5a60d5e11d3f0ba7e.tar.gz
rust-988664ac8a9ae3f53341afd5a60d5e11d3f0ba7e.zip
rustdoc: Fix file locking on windows
If the dwShareMode parameter is 0 on windows, it "prevents other processes from
opening a file or device if they request delete, read, or write access", which
is the opposite of what we want! This changes the 0 parameter to something which
will allow multiple processes to open the file and then lock it.
-rw-r--r--src/librustdoc/flock.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/librustdoc/flock.rs b/src/librustdoc/flock.rs
index f5f75575113..c1e5d66b1d2 100644
--- a/src/librustdoc/flock.rs
+++ b/src/librustdoc/flock.rs
@@ -135,6 +135,7 @@ mod imp {
     use std::libc;
     use std::mem;
     use std::os::win32::as_utf16_p;
+    use std::os;
     use std::ptr;
 
     static LOCKFILE_EXCLUSIVE_LOCK: libc::DWORD = 0x00000002;
@@ -160,12 +161,20 @@ mod imp {
     impl Lock {
         pub fn new(p: &Path) -> Lock {
             let handle = as_utf16_p(p.as_str().unwrap(), |p| unsafe {
-                libc::CreateFileW(p, libc::GENERIC_READ, 0, ptr::mut_null(),
+                libc::CreateFileW(p,
+                                  libc::FILE_GENERIC_READ |
+                                    libc::FILE_GENERIC_WRITE,
+                                  libc::FILE_SHARE_READ |
+                                    libc::FILE_SHARE_DELETE |
+                                    libc::FILE_SHARE_WRITE,
+                                  ptr::mut_null(),
                                   libc::CREATE_ALWAYS,
                                   libc::FILE_ATTRIBUTE_NORMAL,
                                   ptr::mut_null())
             });
-            assert!(handle as uint != libc::INVALID_HANDLE_VALUE as uint);
+            if handle as uint == libc::INVALID_HANDLE_VALUE as uint {
+                fail!("create file error: {}", os::last_os_error());
+            }
             let mut overlapped: libc::OVERLAPPED = unsafe { mem::init() };
             let ret = unsafe {
                 LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0,
@@ -173,7 +182,8 @@ mod imp {
             };
             if ret == 0 {
                 unsafe { libc::CloseHandle(handle); }
-                fail!("could not lock `{}`", p.display())
+                fail!("could not lock `{}`: {}", p.display(),
+                      os::last_os_error())
             }
             Lock { handle: handle }
         }