Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Fix file locking on windows #13043

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/librustdoc/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -160,20 +161,29 @@ 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,
&mut overlapped)
};
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 }
}
Expand Down