Skip to content

Commit

Permalink
Propagate thread creation error in flock
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 16, 2023
1 parent c26438e commit 34c44ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/flock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::error::Result;
use once_cell::sync::OnceCell;
use std::fs::{self, File, OpenOptions};
use std::io;
Expand Down Expand Up @@ -32,11 +33,11 @@ enum FileLock {
}

impl Lock {
pub fn acquire(path: impl AsRef<Path>) -> Self {
Lock {
pub fn acquire(path: impl AsRef<Path>) -> Result<Self> {
Ok(Lock {
intraprocess_guard: Guard::acquire(),
lockfile: FileLock::acquire(path),
}
lockfile: FileLock::acquire(path)?,
})
}
}

Expand All @@ -51,18 +52,18 @@ impl Guard {
}

impl FileLock {
fn acquire(path: impl AsRef<Path>) -> Self {
fn acquire(path: impl AsRef<Path>) -> Result<Self> {
let path = path.as_ref().to_owned();
let lockfile = match create(&path) {
None => return FileLock::NotLocked,
None => return Ok(FileLock::NotLocked),
Some(lockfile) => lockfile,
};
let done = Arc::new(AtomicBool::new(false));
thread::spawn({
thread::Builder::new().spawn({
let done = Arc::clone(&done);
move || poll(lockfile, done)
});
FileLock::Locked { path, done }
})?;
Ok(FileLock::Locked { path, done })
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Runner {

let (project, _lock) = (|| {
let mut project = self.prepare(&tests)?;
let lock = Lock::acquire(path!(project.dir / ".lock"));
let lock = Lock::acquire(path!(project.dir / ".lock"))?;
self.write(&mut project)?;
Ok((project, lock))
})()
Expand Down

0 comments on commit 34c44ff

Please sign in to comment.