Skip to content

Commit 95d3cf3

Browse files
incr.comp.: Move lock files out of directory being locked
1 parent d1d8258 commit 95d3cf3

File tree

5 files changed

+301
-186
lines changed

5 files changed

+301
-186
lines changed

src/librustc/session/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,25 +366,31 @@ impl Session {
366366
pub fn mark_incr_comp_session_as_invalid(&self) {
367367
let mut incr_comp_session = self.incr_comp_session.borrow_mut();
368368

369-
if let IncrCompSession::Active { .. } = *incr_comp_session { } else {
370-
bug!("Trying to invalidate IncrCompSession `{:?}`", *incr_comp_session)
371-
}
369+
let session_directory = match *incr_comp_session {
370+
IncrCompSession::Active { ref session_directory, .. } => {
371+
session_directory.clone()
372+
}
373+
_ => bug!("Trying to invalidate IncrCompSession `{:?}`",
374+
*incr_comp_session),
375+
};
372376

373377
// Note: This will also drop the lock file, thus unlocking the directory
374-
*incr_comp_session = IncrCompSession::InvalidBecauseOfErrors;
378+
*incr_comp_session = IncrCompSession::InvalidBecauseOfErrors {
379+
session_directory: session_directory
380+
};
375381
}
376382

377383
pub fn incr_comp_session_dir(&self) -> cell::Ref<PathBuf> {
378384
let incr_comp_session = self.incr_comp_session.borrow();
379385
cell::Ref::map(incr_comp_session, |incr_comp_session| {
380386
match *incr_comp_session {
381-
IncrCompSession::NotInitialized |
382-
IncrCompSession::InvalidBecauseOfErrors => {
387+
IncrCompSession::NotInitialized => {
383388
bug!("Trying to get session directory from IncrCompSession `{:?}`",
384389
*incr_comp_session)
385390
}
386391
IncrCompSession::Active { ref session_directory, .. } |
387-
IncrCompSession::Finalized { ref session_directory } => {
392+
IncrCompSession::Finalized { ref session_directory } |
393+
IncrCompSession::InvalidBecauseOfErrors { ref session_directory } => {
388394
session_directory
389395
}
390396
}
@@ -541,7 +547,9 @@ pub enum IncrCompSession {
541547
// This is an error state that is reached when some compilation error has
542548
// occurred. It indicates that the contents of the session directory must
543549
// not be used, since they might be invalid.
544-
InvalidBecauseOfErrors,
550+
InvalidBecauseOfErrors {
551+
session_directory: PathBuf,
552+
}
545553
}
546554

547555
fn init_llvm(sess: &Session) {

src/librustc_data_structures/flock.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,18 @@ mod imp {
220220
use std::path::Path;
221221
use std::fs::{File, OpenOptions};
222222
use std::os::raw::{c_ulong, c_ulonglong, c_int};
223-
use std::os::windows::fs::OpenOptionsExt;
224223

225-
pub type DWORD = c_ulong;
226-
pub type BOOL = c_int;
227-
pub type ULONG_PTR = c_ulonglong;
224+
type DWORD = c_ulong;
225+
type BOOL = c_int;
226+
type ULONG_PTR = c_ulonglong;
228227

229228
type LPOVERLAPPED = *mut OVERLAPPED;
230229
const LOCKFILE_EXCLUSIVE_LOCK: DWORD = 0x00000002;
231230
const LOCKFILE_FAIL_IMMEDIATELY: DWORD = 0x00000001;
232231

233-
pub const FILE_SHARE_DELETE: DWORD = 0x4;
234-
pub const FILE_SHARE_READ: DWORD = 0x1;
235-
pub const FILE_SHARE_WRITE: DWORD = 0x2;
232+
const FILE_SHARE_DELETE: DWORD = 0x4;
233+
const FILE_SHARE_READ: DWORD = 0x1;
234+
const FILE_SHARE_WRITE: DWORD = 0x2;
236235

237236
#[repr(C)]
238237
struct OVERLAPPED {
@@ -263,19 +262,30 @@ mod imp {
263262
create: bool,
264263
exclusive: bool)
265264
-> io::Result<Lock> {
265+
assert!(p.parent().unwrap().exists(),
266+
"Parent directory of lock-file must exist: {}",
267+
p.display());
266268

267269
let share_mode = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
268270

269-
let f = {
270-
let mut open_options = OpenOptions::new().read(true)
271-
.share_mode(share_mode);
272-
if create {
273-
open_options.create(true);
274-
}
271+
let mut open_options = OpenOptions::new();
272+
open_options.read(true)
273+
.share_mode(share_mode);
274+
275+
if create {
276+
open_options.create(true)
277+
.write(true);
278+
}
275279

276-
match open_options.open(p) {
277-
Ok(file) => file,
278-
Err(err) => return Err(err),
280+
debug!("Attempting to open lock file `{}`", p.display());
281+
let file = match open_options.open(p) {
282+
Ok(file) => {
283+
debug!("Lock file opened successfully");
284+
file
285+
}
286+
Err(err) => {
287+
debug!("Error opening lock file: {}", err);
288+
return Err(err)
279289
}
280290
};
281291

@@ -291,17 +301,22 @@ mod imp {
291301
dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
292302
}
293303

294-
LockFileEx(f.as_raw_handle(),
304+
debug!("Attempting to acquire lock on lock file `{}`",
305+
p.display());
306+
LockFileEx(file.as_raw_handle(),
295307
dwFlags,
296308
0,
297309
0xFFFF_FFFF,
298310
0xFFFF_FFFF,
299311
&mut overlapped)
300312
};
301313
if ret == 0 {
302-
Err(io::Error::last_os_error())
314+
let err = io::Error::last_os_error();
315+
debug!("Failed acquiring file lock: {}", err);
316+
Err(err)
303317
} else {
304-
Ok(Lock { _file: f })
318+
debug!("Successfully acquired lock.");
319+
Ok(Lock { _file: file })
305320
}
306321
}
307322
}

src/librustc_data_structures/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#![feature(staged_api)]
3131
#![feature(unboxed_closures)]
3232
#![feature(fn_traits)]
33-
#![feature(libc)]
3433

34+
#![cfg_attr(unix, feature(libc))]
3535
#![cfg_attr(test, feature(test))]
3636

3737
extern crate core;

0 commit comments

Comments
 (0)