mirror of
https://github.com/starship/starship.git
synced 2024-11-21 15:53:38 +01:00
fix(windows): avoid verbatim paths (#3638)
This commit is contained in:
parent
bfff44fddb
commit
1a8aa96b7f
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -496,6 +496,12 @@ version = "0.11.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1"
|
checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dunce"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "easy-parallel"
|
name = "easy-parallel"
|
||||||
version = "3.2.0"
|
version = "3.2.0"
|
||||||
@ -1605,6 +1611,7 @@ dependencies = [
|
|||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
"directories-next",
|
"directories-next",
|
||||||
|
"dunce",
|
||||||
"gethostname",
|
"gethostname",
|
||||||
"git2",
|
"git2",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
@ -33,6 +33,7 @@ chrono = "0.4.19"
|
|||||||
clap = { version = "3.1.0", features = ["derive", "cargo", "unicode"] }
|
clap = { version = "3.1.0", features = ["derive", "cargo", "unicode"] }
|
||||||
clap_complete = "3.1.0"
|
clap_complete = "3.1.0"
|
||||||
directories-next = "2.0.0"
|
directories-next = "2.0.0"
|
||||||
|
dunce = "1.0.2"
|
||||||
gethostname = "0.2.2"
|
gethostname = "0.2.2"
|
||||||
git2 = { version = "0.13.25", default-features = false }
|
git2 = { version = "0.13.25", default-features = false }
|
||||||
indexmap = { version = "1.8.0", features = ["serde"] }
|
indexmap = { version = "1.8.0", features = ["serde"] }
|
||||||
|
@ -3,4 +3,6 @@ disallowed-methods = [
|
|||||||
"std::process::Command::new",
|
"std::process::Command::new",
|
||||||
# Setting environment variables can cause issues with non-rust code
|
# Setting environment variables can cause issues with non-rust code
|
||||||
"std::env::set_var",
|
"std::env::set_var",
|
||||||
|
# use `dunce` to avoid UNC/verbatim paths, where possible
|
||||||
|
"std::fs::canonicalize",
|
||||||
]
|
]
|
||||||
|
@ -137,9 +137,9 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Canonicalize the current path to resolve symlinks, etc.
|
// Canonicalize the current path to resolve symlinks, etc.
|
||||||
// NOTE: On Windows this converts the path to extended-path syntax.
|
// NOTE: On Windows this may convert the path to extended-path syntax.
|
||||||
let current_dir = Context::expand_tilde(path);
|
let current_dir = Context::expand_tilde(path);
|
||||||
let current_dir = current_dir.canonicalize().unwrap_or(current_dir);
|
let current_dir = dunce::canonicalize(¤t_dir).unwrap_or(current_dir);
|
||||||
let logical_dir = logical_path;
|
let logical_dir = logical_path;
|
||||||
|
|
||||||
let root_config = config
|
let root_config = config
|
||||||
@ -734,10 +734,8 @@ mod tests {
|
|||||||
|
|
||||||
assert_ne!(context.current_dir, context.logical_dir);
|
assert_ne!(context.current_dir, context.logical_dir);
|
||||||
|
|
||||||
let expected_current_dir = path_actual
|
let expected_current_dir =
|
||||||
.join("yyy")
|
dunce::canonicalize(path_actual.join("yyy")).expect("canonicalize");
|
||||||
.canonicalize()
|
|
||||||
.expect("canonicalize");
|
|
||||||
assert_eq!(expected_current_dir, context.current_dir);
|
assert_eq!(expected_current_dir, context.current_dir);
|
||||||
|
|
||||||
let expected_logical_dir = test_path;
|
let expected_logical_dir = test_path;
|
||||||
@ -787,4 +785,21 @@ mod tests {
|
|||||||
let expected_logical_dir = test_path;
|
let expected_logical_dir = test_path;
|
||||||
assert_eq!(expected_logical_dir, context.logical_dir);
|
assert_eq!(expected_logical_dir, context.logical_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[test]
|
||||||
|
fn strip_extended_path_prefix() {
|
||||||
|
let test_path = Path::new(r"\\?\C:\").to_path_buf();
|
||||||
|
let context = Context::new_with_shell_and_path(
|
||||||
|
Properties::default(),
|
||||||
|
Shell::Unknown,
|
||||||
|
Target::Main,
|
||||||
|
test_path.clone(),
|
||||||
|
test_path,
|
||||||
|
);
|
||||||
|
|
||||||
|
let expected_path = Path::new(r"C:\");
|
||||||
|
|
||||||
|
assert_eq!(&context.current_dir, expected_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,8 +364,8 @@ mod tests {
|
|||||||
fs::create_dir_all(&src_dir)?;
|
fs::create_dir_all(&src_dir)?;
|
||||||
init_repo(&repo_dir)?;
|
init_repo(&repo_dir)?;
|
||||||
|
|
||||||
let src_variations = [src_dir.clone(), src_dir.canonicalize().unwrap()];
|
let src_variations = [src_dir.clone(), dunce::canonicalize(src_dir).unwrap()];
|
||||||
let repo_variations = [repo_dir.clone(), repo_dir.canonicalize().unwrap()];
|
let repo_variations = [repo_dir.clone(), dunce::canonicalize(repo_dir).unwrap()];
|
||||||
for src_dir in &src_variations {
|
for src_dir in &src_variations {
|
||||||
for repo_dir in &repo_variations {
|
for repo_dir in &repo_variations {
|
||||||
let output = contract_repo_path(src_dir, repo_dir);
|
let output = contract_repo_path(src_dir, repo_dir);
|
||||||
@ -1590,7 +1590,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn windows_trims_extended_unc_path_prefix() {
|
fn windows_trims_extended_unc_path_prefix() {
|
||||||
// Under Windows, path canonicalization returns UNC paths using extended-path prefixes `\\?\UNC\`
|
// Under Windows, path canonicalization may return UNC paths using extended-path prefixes `\\?\UNC\`
|
||||||
// We expect this prefix to be trimmed before being rendered.
|
// We expect this prefix to be trimmed before being rendered.
|
||||||
let unc_path = Path::new(r"\\?\UNC\server\share\a\b\c");
|
let unc_path = Path::new(r"\\?\UNC\server\share\a\b\c");
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ mod tests {
|
|||||||
fn render_valid_paths() -> io::Result<()> {
|
fn render_valid_paths() -> io::Result<()> {
|
||||||
use io::Write;
|
use io::Write;
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
let root = std::fs::canonicalize(dir.path())?;
|
let root = dunce::canonicalize(dir.path())?;
|
||||||
let mut yaml = File::create(root.join("Pulumi.yml"))?;
|
let mut yaml = File::create(root.join("Pulumi.yml"))?;
|
||||||
yaml.write_all("name: starship\nruntime: nodejs\ndescription: A thing\n".as_bytes())?;
|
yaml.write_all("name: starship\nruntime: nodejs\ndescription: A thing\n".as_bytes())?;
|
||||||
yaml.sync_all()?;
|
yaml.sync_all()?;
|
||||||
@ -337,7 +337,7 @@ mod tests {
|
|||||||
fn partial_login() -> io::Result<()> {
|
fn partial_login() -> io::Result<()> {
|
||||||
use io::Write;
|
use io::Write;
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
let root = std::fs::canonicalize(dir.path())?;
|
let root = dunce::canonicalize(dir.path())?;
|
||||||
let mut yaml = File::create(root.join("Pulumi.yml"))?;
|
let mut yaml = File::create(root.join("Pulumi.yml"))?;
|
||||||
yaml.write_all("name: starship\nruntime: nodejs\ndescription: A thing\n".as_bytes())?;
|
yaml.write_all("name: starship\nruntime: nodejs\ndescription: A thing\n".as_bytes())?;
|
||||||
yaml.sync_all()?;
|
yaml.sync_all()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user