mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2408 from Foryah/issue-2346
touch: change the error message to match the GNU error message #2346
This commit is contained in:
commit
553f70b06a
2 changed files with 44 additions and 1 deletions
|
@ -166,7 +166,15 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = File::create(path) {
|
if let Err(e) = File::create(path) {
|
||||||
show_warning!("cannot touch '{}': {}", path, e);
|
match e.kind() {
|
||||||
|
std::io::ErrorKind::NotFound => {
|
||||||
|
show_error!("cannot touch '{}': {}", path, "No such file or directory")
|
||||||
|
}
|
||||||
|
std::io::ErrorKind::PermissionDenied => {
|
||||||
|
show_error!("cannot touch '{}': {}", path, "Permission denied")
|
||||||
|
}
|
||||||
|
_ => show_error!("cannot touch '{}': {}", path, e),
|
||||||
|
}
|
||||||
error_code = 1;
|
error_code = 1;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@ use self::touch::filetime::{self, FileTime};
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
|
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
|
||||||
let m = at.metadata(path);
|
let m = at.metadata(path);
|
||||||
|
@ -466,3 +467,37 @@ fn test_touch_trailing_slash() {
|
||||||
let file = "no-file/";
|
let file = "no-file/";
|
||||||
ucmd.args(&[file]).fails();
|
ucmd.args(&[file]).fails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_touch_no_such_file_error_msg() {
|
||||||
|
let dirname = "nonexistent";
|
||||||
|
let filename = "file";
|
||||||
|
let path = PathBuf::from(dirname).join(filename);
|
||||||
|
let path_str = path.to_str().unwrap();
|
||||||
|
|
||||||
|
new_ucmd!().arg(&path).fails().stderr_only(format!(
|
||||||
|
"touch: cannot touch '{}': No such file or directory",
|
||||||
|
path_str
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn test_touch_permission_denied_error_msg() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let dirname = "dir_with_read_only_access";
|
||||||
|
let filename = "file";
|
||||||
|
let path = PathBuf::from(dirname).join(filename);
|
||||||
|
let path_str = path.to_str().unwrap();
|
||||||
|
|
||||||
|
// create dest without write permissions
|
||||||
|
at.mkdir(dirname);
|
||||||
|
at.set_readonly(dirname);
|
||||||
|
|
||||||
|
let full_path = at.plus_as_string(path_str);
|
||||||
|
ucmd.arg(&full_path).fails().stderr_only(format!(
|
||||||
|
"touch: cannot touch '{}': Permission denied",
|
||||||
|
&full_path
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue