Skip to content

Commit

Permalink
rustdoc: Fix file locking on windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Mar 21, 2014
1 parent 7334c11 commit 988664a
Showing 1 changed file with 13 additions and 3 deletions.
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

5 comments on commit 988664a

@bors
Copy link
Contributor

@bors bors commented on 988664a Mar 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@988664a

@bors
Copy link
Contributor

@bors bors commented on 988664a Mar 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/fix-rustdoc-windows = 988664a into auto

@bors
Copy link
Contributor

@bors bors commented on 988664a Mar 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/fix-rustdoc-windows = 988664a merged ok, testing candidate = 3e3a3cf

@bors
Copy link
Contributor

@bors bors commented on 988664a Mar 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 988664a Mar 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3e3a3cf

Please sign in to comment.