Path migration part 3: $nu paths (#13368)

# Description
Part 3 of replacing `std::path` types with `nu_path` types added in
#13115. This PR targets the paths listed in `$nu`. That is, the home,
config, data, and cache directories.
This commit is contained in:
Ian Manske
2024-08-01 08:16:31 +00:00
committed by GitHub
parent ca73d85c09
commit ae5fed41ed
14 changed files with 90 additions and 92 deletions

View File

@@ -121,7 +121,7 @@ pub(crate) fn read_config_file(
}
}
eval_config_contents(config_path, engine_state, stack);
eval_config_contents(config_path.into(), engine_state, stack);
}
}
@@ -141,7 +141,7 @@ pub(crate) fn read_loginshell_file(engine_state: &mut EngineState, stack: &mut S
warn!("loginshell_file: {}", config_path.display());
if config_path.exists() {
eval_config_contents(config_path, engine_state, stack);
eval_config_contents(config_path.into(), engine_state, stack);
}
}
}
@@ -302,7 +302,7 @@ pub(crate) fn set_config_path(
Some(s) => canonicalize_with(&s.item, cwd).ok(),
None => nu_path::config_dir().map(|mut p| {
p.push(NUSHELL_FOLDER);
let mut p = canonicalize_with(&p, cwd).unwrap_or(p);
let mut p = canonicalize_with(&p, cwd).unwrap_or(p.into());
p.push(default_config_name);
canonicalize_with(&p, cwd).unwrap_or(p)
}),

View File

@@ -79,7 +79,7 @@ fn main() -> Result<()> {
// there is an error reading it, these values will be used.
let nushell_config_path = if let Some(mut path) = nu_path::config_dir() {
path.push("nushell");
path
path.into()
} else {
// Not really sure what to default this to if nu_path::config_dir() returns None
std::path::PathBuf::new()
@@ -99,8 +99,9 @@ fn main() -> Result<()> {
default: nushell_config_path.display().to_string(),
},
);
} else if let Some(old_config) =
nu_path::get_canonicalized_path(dirs::config_dir()).map(|p| p.join("nushell"))
} else if let Some(old_config) = dirs::config_dir()
.and_then(|p| p.canonicalize().ok())
.map(|p| p.join("nushell"))
{
let xdg_config_empty = nushell_config_path
.read_dir()
@@ -125,7 +126,7 @@ fn main() -> Result<()> {
let default_nushell_completions_path = if let Some(mut path) = nu_path::data_dir() {
path.push("nushell");
path.push("completions");
path
path.into()
} else {
std::path::PathBuf::new()
};
@@ -220,7 +221,7 @@ fn main() -> Result<()> {
start_time = std::time::Instant::now();
set_config_path(
&mut engine_state,
&init_cwd,
init_cwd.as_ref(),
"config.nu",
"config-path",
parsed_nu_cli_args.config_file.as_ref(),
@@ -228,7 +229,7 @@ fn main() -> Result<()> {
set_config_path(
&mut engine_state,
&init_cwd,
init_cwd.as_ref(),
"env.nu",
"env-path",
parsed_nu_cli_args.env_file.as_ref(),
@@ -257,7 +258,7 @@ fn main() -> Result<()> {
start_time = std::time::Instant::now();
// First, set up env vars as strings only
gather_parent_env_vars(&mut engine_state, &init_cwd);
gather_parent_env_vars(&mut engine_state, init_cwd.as_ref());
perf!("gather env vars", start_time, use_color);
engine_state.add_env_var(