Lightweight coding agent that runs in your terminal
Rust
chore: Rust 1.89 promoted file locking to the standard library, so prefer stdlib to fs2 (#2467)
Michael Boline58125e6c10a
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lockindex 80809434e3..dc9385d990 100644--- a/codex-rs/Cargo.lock+++ b/codex-rs/Cargo.lock@@ -703,7 +703,6 @@ dependencies = ["dirs","env-flags","eventsource-stream",- "fs2","futures","landlock","libc",@@ -1745,16 +1744,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 = "futures"version = "0.3.31"diff --git a/codex-rs/core/Cargo.toml b/codex-rs/core/Cargo.tomlindex 78942ff69f..52c731ae66 100644--- a/codex-rs/core/Cargo.toml+++ b/codex-rs/core/Cargo.toml@@ -23,7 +23,6 @@ codex-protocol = { path = "../protocol" }dirs = "6"env-flags = "0.1.1"eventsource-stream = "0.2.3"-fs2 = "0.4.3"futures = "0.3"libc = "0.2.175"mcp-types = { path = "../mcp-types" }diff --git a/codex-rs/core/src/message_history.rs b/codex-rs/core/src/message_history.rsindex 29970c2a74..9f13ababb7 100644--- a/codex-rs/core/src/message_history.rs+++ b/codex-rs/core/src/message_history.rs@@ -125,16 +125,18 @@ pub(crate) async fn append_entry(text: &str, session_id: &Uuid, config: &Config)/// times if the lock is currently held by another process. This prevents a/// potential indefinite wait while still giving other writers some time to/// finish their operation.-async fn acquire_exclusive_lock_with_retry(file: &std::fs::File) -> Result<()> {+async fn acquire_exclusive_lock_with_retry(file: &File) -> Result<()> {use tokio::time::sleep;for _ in 0..MAX_RETRIES {- match fs2::FileExt::try_lock_exclusive(file) {+ match file.try_lock() {Ok(()) => return Ok(()),- Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {- sleep(RETRY_SLEEP).await;- }- Err(e) => return Err(e),+ Err(e) => match e {+ std::fs::TryLockError::WouldBlock => {+ sleep(RETRY_SLEEP).await;+ }+ other => return Err(other.into()),+ },}}@@ -259,12 +261,14 @@ pub(crate) fn lookup(log_id: u64, offset: usize, config: &Config) -> Option<Hist#[cfg(unix)]fn acquire_shared_lock_with_retry(file: &File) -> Result<()> {for _ in 0..MAX_RETRIES {- match fs2::FileExt::try_lock_shared(file) {+ match file.try_lock_shared() {Ok(()) => return Ok(()),- Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {- std::thread::sleep(RETRY_SLEEP);- }- Err(e) => return Err(e),+ Err(e) => match e {+ std::fs::TryLockError::WouldBlock => {+ std::thread::sleep(RETRY_SLEEP);+ }+ other => return Err(other.into()),+ },}}