mirror of
https://github.com/openai/codex.git
synced 2026-11-28 07:32:19 +00:00
Use AbsolutePathBuf in skill loading and codex_home (#17407)
Helps with FS migration later
This commit is contained in:
1 parent
d25a9822a7
commit
ac82443d07
86 files changed
+850
-625
No files matched your search
@@ -1,3 +1,4 @@
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use dirs::home_dir;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -9,14 +10,14 @@ use std::path::PathBuf;
|
||||
/// value will be canonicalized and this function will Err otherwise.
|
||||
/// - If `CODEX_HOME` is not set, this function does not verify that the
|
||||
/// directory exists.
|
||||
pub fn find_codex_home() -> std::io::Result<PathBuf> {
|
||||
pub fn find_codex_home() -> std::io::Result<AbsolutePathBuf> {
|
||||
let codex_home_env = std::env::var("CODEX_HOME")
|
||||
.ok()
|
||||
.filter(|val| !val.is_empty());
|
||||
find_codex_home_from_env(codex_home_env.as_deref())
|
||||
}
|
||||
|
||||
fn find_codex_home_from_env(codex_home_env: Option<&str>) -> std::io::Result<PathBuf> {
|
||||
fn find_codex_home_from_env(codex_home_env: Option<&str>) -> std::io::Result<AbsolutePathBuf> {
|
||||
// Honor the `CODEX_HOME` environment variable when it is set to allow users
|
||||
// (and tests) to override the default location.
|
||||
match codex_home_env {
|
||||
@@ -39,12 +40,13 @@ fn find_codex_home_from_env(codex_home_env: Option<&str>) -> std::io::Result<Pat
|
||||
format!("CODEX_HOME points to {val:?}, but that path is not a directory"),
|
||||
))
|
||||
} else {
|
||||
path.canonicalize().map_err(|err| {
|
||||
let canonical = path.canonicalize().map_err(|err| {
|
||||
std::io::Error::new(
|
||||
err.kind(),
|
||||
format!("failed to canonicalize CODEX_HOME {val:?}: {err}"),
|
||||
)
|
||||
})
|
||||
})?;
|
||||
AbsolutePathBuf::from_absolute_path(canonical)
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -55,7 +57,7 @@ fn find_codex_home_from_env(codex_home_env: Option<&str>) -> std::io::Result<Pat
|
||||
)
|
||||
})?;
|
||||
p.push(".codex");
|
||||
Ok(p)
|
||||
AbsolutePathBuf::from_absolute_path(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +65,7 @@ fn find_codex_home_from_env(codex_home_env: Option<&str>) -> std::io::Result<Pat
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::find_codex_home_from_env;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use dirs::home_dir;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::fs;
|
||||
@@ -115,6 +118,7 @@ mod tests {
|
||||
.path()
|
||||
.canonicalize()
|
||||
.expect("canonicalize temp home");
|
||||
let expected = AbsolutePathBuf::from_absolute_path(expected).expect("absolute home");
|
||||
assert_eq!(resolved, expected);
|
||||
}
|
||||
|
||||
@@ -124,6 +128,7 @@ mod tests {
|
||||
find_codex_home_from_env(/*codex_home_env*/ None).expect("default CODEX_HOME");
|
||||
let mut expected = home_dir().expect("home dir");
|
||||
expected.push(".codex");
|
||||
let expected = AbsolutePathBuf::from_absolute_path(expected).expect("absolute home");
|
||||
assert_eq!(resolved, expected);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user