shred: fails in case of permissions issue

This commit is contained in:
Sylvestre Ledru 2024-03-16 11:33:58 +01:00
parent 844f077401
commit bb5111cc71
2 changed files with 27 additions and 1 deletions

View file

@ -365,6 +365,7 @@ fn get_size(size_str_opt: Option<String>) -> Option<u64> {
.or_else(|| {
if let Some(size) = size_str_opt {
show_error!("invalid file size: {}", size.quote());
// TODO: replace with our error management
std::process::exit(1);
}
None
@ -578,7 +579,8 @@ fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> Op
new_path.quote(),
e
);
return None;
// TODO: replace with our error management
std::process::exit(1);
}
}
}

View file

@ -6,6 +6,7 @@
// spell-checker:ignore wipesync
use crate::common::util::TestScenario;
use std::path::Path;
#[test]
fn test_invalid_arg() {
@ -163,3 +164,26 @@ fn test_shred_empty() {
assert!(!at.file_exists(file_a));
}
#[test]
#[cfg(all(unix, feature = "chmod"))]
fn test_shred_fail_no_perm() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let dir = "dir";
let file = "test_shred_remove_a";
let binding = Path::new("dir").join(file);
let path = binding.to_str().unwrap();
at.mkdir(dir);
at.touch(path);
scene.ccmd("chmod").arg("a-w").arg(dir).succeeds();
scene
.ucmd()
.arg("-uv")
.arg(path)
.fails()
.stderr_contains("Couldn't rename to");
}