mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-17 05:02:45 +08:00
Don't use $HOME under cargo test harness
We will continue to use the "normal" fish base directory detection when using the CMake test harness which properly sets up a sandboxed $HOME for fish to use, but when running source code tests with a bare `cargo test` we don't want to write to the actual user's profile. This also works around test failures when running `cargo test` under CI with a locked-down $HOME directory (see #10474).
This commit is contained in:
parent
eba0d56411
commit
a35925b3ed
27
src/path.rs
27
src/path.rs
|
@ -594,7 +594,34 @@ impl BaseDirectory {
|
|||
/// Attempt to get a base directory, creating it if necessary. If a variable named \p xdg_var is
|
||||
/// set, use that directory; otherwise use the path \p non_xdg_homepath rooted in $HOME. \return the
|
||||
/// result; see the base_directory_t fields.
|
||||
#[cfg_attr(test, allow(unused_variables), allow(unreachable_code))]
|
||||
fn make_base_directory(xdg_var: &wstr, non_xdg_homepath: &wstr) -> BaseDirectory {
|
||||
#[cfg(test)]
|
||||
// If running under `cargo test`, contain ourselves to the build directory and do not try to use
|
||||
// the actual $HOME or $XDG_XXX directories. This prevents the tests from failing and/or stops
|
||||
// the tests polluting the user's actual $HOME if a sandbox environment has not been set up.
|
||||
{
|
||||
use crate::common::str2wcstring;
|
||||
use std::path::PathBuf;
|
||||
|
||||
let mut build_dir = PathBuf::from(env!("FISH_BUILD_DIR"));
|
||||
build_dir.push("fish_root");
|
||||
|
||||
let err = match std::fs::create_dir_all(&build_dir) {
|
||||
Ok(_) => 0,
|
||||
Err(e) => e
|
||||
.raw_os_error()
|
||||
.expect("Failed to create fish base directory, but it wasn't an OS error!"),
|
||||
};
|
||||
|
||||
return BaseDirectory {
|
||||
path: str2wcstring(build_dir.as_os_str().as_bytes()),
|
||||
remoteness: DirRemoteness::unknown,
|
||||
used_xdg: false,
|
||||
err,
|
||||
};
|
||||
}
|
||||
|
||||
// The vars we fetch must be exported. Allowing them to be universal doesn't make sense and
|
||||
// allowing that creates a lock inversion that deadlocks the shell since we're called before
|
||||
// uvars are available.
|
||||
|
|
Loading…
Reference in New Issue
Block a user