From 81451f424601b6d21eb32202dea94dad4f01da3b Mon Sep 17 00:00:00 2001 From: jif-oai Date: Thu, 4 Sep 2025 13:39:55 -0700 Subject: [PATCH] Update codex-rs/core/src/shell.rs Co-authored-by: Michael Bolin --- codex-rs/core/src/shell.rs | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/codex-rs/core/src/shell.rs b/codex-rs/core/src/shell.rs index 83af78d9c2..1c08dcb6fa 100644 --- a/codex-rs/core/src/shell.rs +++ b/codex-rs/core/src/shell.rs @@ -232,32 +232,26 @@ async fn ensure_zsh_snapshot(shell_path: &str, home: &Path, session_id: Uuid) -> let snapshot_path = home.join(format!(".codex_shell_snapshot_{session_id}.zsh")); // Check if an update in the profile requires to re-generate the snapshot. - let snapshot_is_stale = match tokio::fs::metadata(&snapshot_path).await { - Ok(metadata) => match metadata.modified() { - Ok(snapshot_modified) => { - let mut stale = false; - for profile in zsh_profile_paths(home) { - if let Ok(profile_metadata) = tokio::fs::metadata(&profile).await { - match profile_metadata.modified() { - Ok(profile_modified) => { - if profile_modified > snapshot_modified { - stale = true; - break; - } - } - Err(_) => { - stale = true; - break; - } - } - } - } - stale - } - Err(_) => true, - }, - Err(_) => true, - }; +let snapshot_is_stale = async { + let snapshot_metadata = tokio::fs::metadata(&snapshot_path).await.ok()?; + let snapshot_modified = snapshot_metadata.modified().ok()?; + + for profile in zsh_profile_paths(home) { + let Ok(profile_metadata) = tokio::fs::metadata(&profile).await else { + continue; + }; + + let Ok(profile_modified) = profile_metadata.modified() else { + return Some(true); + }; + + if profile_modified > snapshot_modified { + return Some(true); + } + } + + Some(false) +}.await.unwrap_or(true); if !snapshot_is_stale { return Some(snapshot_path);