mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
add -n for path expand, so it doesn't follow symlink (#6255)
* add -p for path expand, so it doesn't follow symlink * fix arg name * rename from no-dereferenct to no-follow-link * rename from no-follow-link to no-symlink, and change short -p to -n * follow strict first * fix * simplify test * fix clippy * fix test on windows
This commit is contained in:
@ -286,7 +286,7 @@ fn copy_dir_contains_symlink() {
|
||||
// make symbolic link and copy.
|
||||
nu!(
|
||||
cwd: sandbox.cwd(),
|
||||
"rm tmp_dir/good_bye; cp -r -p tmp_dir tmp_dir_2",
|
||||
"rm tmp_dir/good_bye; cp -r -n tmp_dir tmp_dir_2",
|
||||
);
|
||||
|
||||
// check hello_there exists inside `tmp_dir_2`, and `dangle_symlink` also exists inside `tmp_dir_2`.
|
||||
@ -309,7 +309,7 @@ fn copy_dir_symlink_file_body_not_changed() {
|
||||
// make symbolic link and copy.
|
||||
nu!(
|
||||
cwd: sandbox.cwd(),
|
||||
"rm tmp_dir/good_bye; cp -r -p tmp_dir tmp_dir_2; rm -r tmp_dir; cp -r -p tmp_dir_2 tmp_dir; echo hello_data | save tmp_dir/good_bye",
|
||||
"rm tmp_dir/good_bye; cp -r -n tmp_dir tmp_dir_2; rm -r tmp_dir; cp -r -n tmp_dir_2 tmp_dir; echo hello_data | save tmp_dir/good_bye",
|
||||
);
|
||||
|
||||
// check dangle_symlink in tmp_dir is no longer dangling.
|
||||
|
@ -24,6 +24,28 @@ fn expands_path_with_dot() {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn expands_path_without_follow_symlink() {
|
||||
Playground::setup("path_expand_3", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ln -s spam.txt menu/spam_link.ln;
|
||||
echo "menu/./spam_link.ln"
|
||||
| path expand -n
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = dirs.test.join("menu").join("spam_link.ln");
|
||||
assert_eq!(PathBuf::from(actual.out), expected);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expands_path_with_double_dot() {
|
||||
Playground::setup("path_expand_2", |dirs, sandbox| {
|
||||
@ -75,4 +97,31 @@ mod windows {
|
||||
assert!(!PathBuf::from(actual.out).starts_with("~"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expands_path_without_follow_symlink() {
|
||||
Playground::setup("path_expand_3", |dirs, sandbox| {
|
||||
sandbox
|
||||
.within("menu")
|
||||
.with_files(vec![EmptyFile("spam.txt")]);
|
||||
|
||||
let cwd = dirs.test();
|
||||
std::os::windows::fs::symlink_file(
|
||||
cwd.join("menu").join("spam.txt"),
|
||||
cwd.join("menu").join("spam_link.ln"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
echo "menu/./spam_link.ln"
|
||||
| path expand -n
|
||||
"#
|
||||
));
|
||||
|
||||
let expected = dirs.test.join("menu").join("spam_link.ln");
|
||||
assert_eq!(PathBuf::from(actual.out), expected);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user