mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
chore: prefer AsRef<Path> to &Path (#8249)
This is some minor API cleanup that will make it easier to use `AbsolutePathBuf` in more places in a subsequent PR.
This commit is contained in:
@@ -470,15 +470,15 @@ fn validate_config(value: &TomlValue) -> Result<(), toml::de::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paths_match(expected: &Path, provided: &Path) -> bool {
|
fn paths_match(expected: impl AsRef<Path>, provided: impl AsRef<Path>) -> bool {
|
||||||
if let (Ok(expanded_expected), Ok(expanded_provided)) = (
|
if let (Ok(expanded_expected), Ok(expanded_provided)) = (
|
||||||
path_utils::normalize_for_path_comparison(expected),
|
path_utils::normalize_for_path_comparison(&expected),
|
||||||
path_utils::normalize_for_path_comparison(provided),
|
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> {
|
fn value_at_path<'a>(root: &'a TomlValue, segments: &[String]) -> Option<&'a TomlValue> {
|
||||||
|
|||||||
@@ -56,27 +56,27 @@ pub(super) async fn load_config_layers_internal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn read_config_from_path(
|
pub(super) async fn read_config_from_path(
|
||||||
path: &Path,
|
path: impl AsRef<Path>,
|
||||||
log_missing_as_info: bool,
|
log_missing_as_info: bool,
|
||||||
) -> io::Result<Option<TomlValue>> {
|
) -> io::Result<Option<TomlValue>> {
|
||||||
match fs::read_to_string(path).await {
|
match fs::read_to_string(path.as_ref()).await {
|
||||||
Ok(contents) => match toml::from_str::<TomlValue>(&contents) {
|
Ok(contents) => match toml::from_str::<TomlValue>(&contents) {
|
||||||
Ok(value) => Ok(Some(value)),
|
Ok(value) => Ok(Some(value)),
|
||||||
Err(err) => {
|
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(io::Error::new(io::ErrorKind::InvalidData, err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
||||||
if log_missing_as_info {
|
if log_missing_as_info {
|
||||||
tracing::info!("{} not found, using defaults", path.display());
|
tracing::info!("{} not found, using defaults", path.as_ref().display());
|
||||||
} else {
|
} else {
|
||||||
tracing::debug!("{} not found", path.display());
|
tracing::debug!("{} not found", path.as_ref().display());
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::error!("Failed to read {}: {err}", path.display());
|
tracing::error!("Failed to read {}: {err}", path.as_ref().display());
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use crate::env;
|
use crate::env;
|
||||||
|
|
||||||
pub fn normalize_for_path_comparison(path: &Path) -> std::io::Result<PathBuf> {
|
pub fn normalize_for_path_comparison(path: impl AsRef<Path>) -> std::io::Result<PathBuf> {
|
||||||
let canonical = path.canonicalize()?;
|
let canonical = path.as_ref().canonicalize()?;
|
||||||
Ok(normalize_for_wsl(canonical))
|
Ok(normalize_for_wsl(canonical))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user