mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
shred: fix --remove=unlink with relative paths
This commit is contained in:
committed by
Daniel Hofstetter
parent
b936d7cd7f
commit
840c36d396
@@ -719,7 +719,7 @@ fn wipe_file(
|
||||
}
|
||||
|
||||
if remove_method != RemoveMethod::None {
|
||||
do_remove(path, path_str, verbose, remove_method).map_err_context(
|
||||
do_remove(path, verbose, remove_method).map_err_context(
|
||||
|| translate!("shred-failed-to-remove-file", "file" => path.maybe_quote()),
|
||||
)?;
|
||||
}
|
||||
@@ -824,21 +824,16 @@ fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> Pa
|
||||
last_path
|
||||
}
|
||||
|
||||
fn do_remove(
|
||||
path: &Path,
|
||||
orig_filename: &OsString,
|
||||
verbose: bool,
|
||||
remove_method: RemoveMethod,
|
||||
) -> Result<(), io::Error> {
|
||||
fn do_remove(path: &Path, verbose: bool, remove_method: RemoveMethod) -> Result<(), io::Error> {
|
||||
if verbose {
|
||||
show_error!(
|
||||
"{}",
|
||||
translate!("shred-removing", "file" => orig_filename.maybe_quote())
|
||||
translate!("shred-removing", "file" => path.maybe_quote())
|
||||
);
|
||||
}
|
||||
|
||||
let remove_path = if remove_method == RemoveMethod::Unlink {
|
||||
path.with_file_name(orig_filename)
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
wipe_name(path, verbose, remove_method)
|
||||
};
|
||||
@@ -848,7 +843,7 @@ fn do_remove(
|
||||
if verbose {
|
||||
show_error!(
|
||||
"{}",
|
||||
translate!("shred-removed", "file" => orig_filename.maybe_quote())
|
||||
translate!("shred-removed", "file" => path.maybe_quote())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,20 @@ fn test_shred_remove_unlink() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shred_remove_unlink_relative_path() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
at.mkdir_all("dir1/dir2");
|
||||
at.write("dir1/dir2/file1", "test data");
|
||||
|
||||
ucmd.arg("--remove=unlink")
|
||||
.arg("dir1/dir2/file1")
|
||||
.succeeds();
|
||||
|
||||
assert!(!at.file_exists("dir1/dir2/file1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shred_remove_wipe() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
Reference in New Issue
Block a user