Skip to content

Commit 3e3a3cf

Browse files
committed
auto merge of #13043 : alexcrichton/rust/fix-rustdoc-windows, r=brson
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.
2 parents cff012d + 988664a commit 3e3a3cf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/librustdoc/flock.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ mod imp {
135135
use std::libc;
136136
use std::mem;
137137
use std::os::win32::as_utf16_p;
138+
use std::os;
138139
use std::ptr;
139140

140141
static LOCKFILE_EXCLUSIVE_LOCK: libc::DWORD = 0x00000002;
@@ -160,20 +161,29 @@ mod imp {
160161
impl Lock {
161162
pub fn new(p: &Path) -> Lock {
162163
let handle = as_utf16_p(p.as_str().unwrap(), |p| unsafe {
163-
libc::CreateFileW(p, libc::GENERIC_READ, 0, ptr::mut_null(),
164+
libc::CreateFileW(p,
165+
libc::FILE_GENERIC_READ |
166+
libc::FILE_GENERIC_WRITE,
167+
libc::FILE_SHARE_READ |
168+
libc::FILE_SHARE_DELETE |
169+
libc::FILE_SHARE_WRITE,
170+
ptr::mut_null(),
164171
libc::CREATE_ALWAYS,
165172
libc::FILE_ATTRIBUTE_NORMAL,
166173
ptr::mut_null())
167174
});
168-
assert!(handle as uint != libc::INVALID_HANDLE_VALUE as uint);
175+
if handle as uint == libc::INVALID_HANDLE_VALUE as uint {
176+
fail!("create file error: {}", os::last_os_error());
177+
}
169178
let mut overlapped: libc::OVERLAPPED = unsafe { mem::init() };
170179
let ret = unsafe {
171180
LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0,
172181
&mut overlapped)
173182
};
174183
if ret == 0 {
175184
unsafe { libc::CloseHandle(handle); }
176-
fail!("could not lock `{}`", p.display())
185+
fail!("could not lock `{}`: {}", p.display(),
186+
os::last_os_error())
177187
}
178188
Lock { handle: handle }
179189
}

0 commit comments

Comments
 (0)