From 08a3cbea668abe5c9555dc319cc66f8965296e83 Mon Sep 17 00:00:00 2001 From: Boni Garcia Date: Mon, 19 Oct 2026 12:25:02 +0200 Subject: [PATCH 1/2] [rust] Remove fs2 crate and use standard mechanism for file lock --- rust/Cargo.lock | 11 ----------- rust/Cargo.toml | 1 - rust/src/lock.rs | 5 ++--- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index ce9f66ccfc260..47a69d5902003 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -735,16 +735,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "fs_extra" version = "1.3.0" @@ -2007,7 +1997,6 @@ dependencies = [ "env_logger", "exitcode", "flate2", - "fs2", "fs_extra", "infer 0.22.0", "is_executable", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index e4b165e2cfabc..b24323f2c2303 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -42,7 +42,6 @@ debpkg = "0.6.0" anyhow = { version = "1.0.104", default-features = false, features = ["backtrace", "std"] } apple-flat-package = "0.20.0" which = "8.0.6" -fs2 = "0.4.3" fs_extra = "1.3.0" [target.'cfg(windows)'.dependencies] diff --git a/rust/src/lock.rs b/rust/src/lock.rs index 621ffdef8b89b..f247707ca5772 100644 --- a/rust/src/lock.rs +++ b/rust/src/lock.rs @@ -22,7 +22,6 @@ use std::fs::File; use std::path::{Path, PathBuf}; use crate::files::{create_parent_path_if_not_exists, create_path_if_not_exists}; -use fs2::FileExt; use std::fs; thread_local!(static LOCK_PATH: RefCell> = const { RefCell::new(None) }); @@ -52,7 +51,7 @@ impl Lock { let file = File::create(&path)?; log.debug(format!("Acquiring lock: {}", path.display())); - file.lock_exclusive().unwrap_or_default(); + file.lock().unwrap_or_default(); set_lock_path(Some(path.to_path_buf())); Ok(Self { @@ -63,7 +62,7 @@ impl Lock { pub fn release(&mut self) { if let Some(file) = self.file.take() { - FileExt::unlock(&file).unwrap_or_default(); + file.unlock().unwrap_or_default(); fs::remove_file(&self.path).unwrap_or_default(); } set_lock_path(None); From c7da14db5052f6f113758addf4ef662af30514db Mon Sep 17 00:00:00 2001 From: Boni Garcia Date: Mon, 19 Oct 2026 12:34:48 +0200 Subject: [PATCH 2/2] [rust] Specify minimum Rust version and add test --- rust/Cargo.toml | 1 + rust/README.md | 2 ++ rust/src/lock.rs | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index b24323f2c2303..5ff0f7d0b4983 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -2,6 +2,7 @@ name = "selenium-manager" version = "0.4.52-nightly" # don't forget to update rust/BUILD.bazel edition = "2024" +rust-version = "1.89" authors = ["Selenium PathBuf { let unique = SystemTime::now() @@ -147,4 +147,37 @@ mod tests { assert!(!lock_path.exists()); fs::remove_dir_all(root).unwrap(); } + + #[test] + fn acquire_blocks_until_lock_is_released() { + let root = create_test_dir("lock_blocked"); + let logger = Logger::new(); + let mut lock = Lock::acquire(&logger, &root, None).unwrap(); + + let (ready_tx, ready_rx) = std::sync::mpsc::channel(); + let (acquired_tx, acquired_rx) = std::sync::mpsc::channel(); + let root_clone = root.clone(); + let handle = std::thread::spawn(move || { + let logger = Logger::new(); + ready_tx.send(()).unwrap(); + let _competing = Lock::acquire(&logger, &root_clone, None).unwrap(); + acquired_tx.send(()).unwrap(); + }); + + ready_rx.recv().unwrap(); + assert!( + acquired_rx + .recv_timeout(Duration::from_millis(200)) + .is_err(), + "competing acquisition must remain blocked while the lock is held" + ); + + lock.release(); + acquired_rx + .recv_timeout(Duration::from_secs(5)) + .expect("competing acquisition must succeed after the lock is released"); + handle.join().unwrap(); + + fs::remove_dir_all(root).unwrap(); + } }