mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
fix removing symlinks on windows (#9704)
this PR should close #9624 # Description Fixes the `rm` command assuming that a symlink is a directory and trying to delete the directory as opposed to unlinking the symlink. Should probably be tested on linux before merge. Added tests for deleting symlinks
This commit is contained in:
committed by
GitHub
parent
c62cbcd5f8
commit
bd9d865912
@ -352,6 +352,29 @@ fn remove_ignores_ansi() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removes_symlink() {
|
||||
let symlink_target = "symlink_target";
|
||||
let symlink = "symlink";
|
||||
Playground::setup("rm_test_symlink", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile(symlink_target)]);
|
||||
|
||||
#[cfg(not(windows))]
|
||||
std::os::unix::fs::symlink(dirs.test().join(symlink_target), dirs.test().join(symlink))
|
||||
.unwrap();
|
||||
#[cfg(windows)]
|
||||
std::os::windows::fs::symlink_file(
|
||||
dirs.test().join(symlink_target),
|
||||
dirs.test().join(symlink),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let _ = nu!(cwd: sandbox.cwd(), "rm symlink");
|
||||
|
||||
assert!(!dirs.test().join(symlink).exists());
|
||||
});
|
||||
}
|
||||
|
||||
struct Cleanup<'a> {
|
||||
dir_to_clean: &'a PathBuf,
|
||||
}
|
||||
|
Reference in New Issue
Block a user