From ac66a9f6f17c386ad26d4ff9b60d2736ea72ff35 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 18 Dec 2025 00:02:35 -0800 Subject: [PATCH] chore: simplify loading of Mac-specific logic in config_loader --- codex-rs/core/src/config/service.rs | 12 ++++++------ codex-rs/core/src/config_loader/layer_io.rs | 14 +++++++------- codex-rs/core/src/path_utils.rs | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/codex-rs/core/src/config/service.rs b/codex-rs/core/src/config/service.rs index 398a74c0d7..e20ebed617 100644 --- a/codex-rs/core/src/config/service.rs +++ b/codex-rs/core/src/config/service.rs @@ -470,15 +470,15 @@ fn validate_config(value: &TomlValue) -> Result<(), toml::de::Error> { Ok(()) } -fn paths_match(expected: &Path, provided: &Path) -> bool { +fn paths_match, Q: AsRef>(expected: P, provided: Q) -> bool { if let (Ok(expanded_expected), Ok(expanded_provided)) = ( - path_utils::normalize_for_path_comparison(expected), - path_utils::normalize_for_path_comparison(provided), + path_utils::normalize_for_path_comparison(&expected), + path_utils::normalize_for_path_comparison(&provided), ) { - return expanded_expected == expanded_provided; + expanded_expected == expanded_provided + } else { + expected.as_ref() == provided.as_ref() } - - expected == provided } fn value_at_path<'a>(root: &'a TomlValue, segments: &[String]) -> Option<&'a TomlValue> { diff --git a/codex-rs/core/src/config_loader/layer_io.rs b/codex-rs/core/src/config_loader/layer_io.rs index 58ccab1942..56d84e209d 100644 --- a/codex-rs/core/src/config_loader/layer_io.rs +++ b/codex-rs/core/src/config_loader/layer_io.rs @@ -55,28 +55,28 @@ pub(super) async fn load_config_layers_internal( }) } -pub(super) async fn read_config_from_path( - path: &Path, +pub(super) async fn read_config_from_path>( + path: P, log_missing_as_info: bool, ) -> io::Result> { - match fs::read_to_string(path).await { + match fs::read_to_string(path.as_ref()).await { Ok(contents) => match toml::from_str::(&contents) { Ok(value) => Ok(Some(value)), Err(err) => { - tracing::error!("Failed to parse {}: {err}", path.display()); + tracing::error!("Failed to parse {}: {err}", path.as_ref().display()); Err(io::Error::new(io::ErrorKind::InvalidData, err)) } }, Err(err) if err.kind() == io::ErrorKind::NotFound => { if log_missing_as_info { - tracing::info!("{} not found, using defaults", path.display()); + tracing::info!("{} not found, using defaults", path.as_ref().display()); } else { - tracing::debug!("{} not found", path.display()); + tracing::debug!("{} not found", path.as_ref().display()); } Ok(None) } Err(err) => { - tracing::error!("Failed to read {}: {err}", path.display()); + tracing::error!("Failed to read {}: {err}", path.as_ref().display()); Err(err) } } diff --git a/codex-rs/core/src/path_utils.rs b/codex-rs/core/src/path_utils.rs index 9a7007e4f1..eaa6195b23 100644 --- a/codex-rs/core/src/path_utils.rs +++ b/codex-rs/core/src/path_utils.rs @@ -3,8 +3,8 @@ use std::path::PathBuf; use crate::env; -pub fn normalize_for_path_comparison(path: &Path) -> std::io::Result { - let canonical = path.canonicalize()?; +pub fn normalize_for_path_comparison>(path: P) -> std::io::Result { + let canonical = path.as_ref().canonicalize()?; Ok(normalize_for_wsl(canonical)) }