chore: Rust 1.89 promoted file locking to the standard library, so prefer stdlib to fs2 (#2467)

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/2467).
* __->__ #2467
* #2465
This commit is contained in:
Michael Bolin
2025-08-19 13:22:46 -07:00
committed by GitHub
parent 50c48e88f5
commit e58125e6c1
3 changed files with 15 additions and 23 deletions

11
codex-rs/Cargo.lock generated
View File

@@ -703,7 +703,6 @@ dependencies = [
"dirs", "dirs",
"env-flags", "env-flags",
"eventsource-stream", "eventsource-stream",
"fs2",
"futures", "futures",
"landlock", "landlock",
"libc", "libc",
@@ -1745,16 +1744,6 @@ dependencies = [
"percent-encoding", "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]] [[package]]
name = "futures" name = "futures"
version = "0.3.31" version = "0.3.31"

View File

@@ -23,7 +23,6 @@ codex-protocol = { path = "../protocol" }
dirs = "6" dirs = "6"
env-flags = "0.1.1" env-flags = "0.1.1"
eventsource-stream = "0.2.3" eventsource-stream = "0.2.3"
fs2 = "0.4.3"
futures = "0.3" futures = "0.3"
libc = "0.2.175" libc = "0.2.175"
mcp-types = { path = "../mcp-types" } mcp-types = { path = "../mcp-types" }

View File

@@ -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 /// times if the lock is currently held by another process. This prevents a
/// potential indefinite wait while still giving other writers some time to /// potential indefinite wait while still giving other writers some time to
/// finish their operation. /// 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; use tokio::time::sleep;
for _ in 0..MAX_RETRIES { for _ in 0..MAX_RETRIES {
match fs2::FileExt::try_lock_exclusive(file) { match file.try_lock() {
Ok(()) => return Ok(()), Ok(()) => return Ok(()),
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { Err(e) => match e {
std::fs::TryLockError::WouldBlock => {
sleep(RETRY_SLEEP).await; sleep(RETRY_SLEEP).await;
} }
Err(e) => return Err(e), other => return Err(other.into()),
},
} }
} }
@@ -259,12 +261,14 @@ pub(crate) fn lookup(log_id: u64, offset: usize, config: &Config) -> Option<Hist
#[cfg(unix)] #[cfg(unix)]
fn acquire_shared_lock_with_retry(file: &File) -> Result<()> { fn acquire_shared_lock_with_retry(file: &File) -> Result<()> {
for _ in 0..MAX_RETRIES { for _ in 0..MAX_RETRIES {
match fs2::FileExt::try_lock_shared(file) { match file.try_lock_shared() {
Ok(()) => return Ok(()), Ok(()) => return Ok(()),
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { Err(e) => match e {
std::fs::TryLockError::WouldBlock => {
std::thread::sleep(RETRY_SLEEP); std::thread::sleep(RETRY_SLEEP);
} }
Err(e) => return Err(e), other => return Err(other.into()),
},
} }
} }