ln: adjust the error messages

This commit is contained in:
Sylvestre Ledru 2022-03-31 13:45:41 +02:00
parent 676283ce93
commit b3d87b088d
3 changed files with 7 additions and 7 deletions

View file

@ -54,7 +54,7 @@ enum LnError {
TargetIsDirectory(PathBuf),
SomeLinksFailed,
FailedToLink(PathBuf, PathBuf, String),
SameFile(PathBuf, PathBuf),
SameFile(),
MissingDestination(PathBuf),
ExtraOperand(OsString),
}
@ -66,8 +66,8 @@ impl Display for LnError {
Self::FailedToLink(s, d, e) => {
write!(f, "failed to link {} to {}: {}", s.quote(), d.quote(), e)
}
Self::SameFile(e, e2) => {
write!(f, "{} and {} are the same file", e2.quote(), e.quote())
Self::SameFile() => {
write!(f, "Same file")
}
Self::SomeLinksFailed => write!(f, "some links failed to create"),
Self::MissingDestination(s) => {
@ -91,7 +91,7 @@ impl UError for LnError {
Self::TargetIsDirectory(_)
| Self::SomeLinksFailed
| Self::FailedToLink(_, _, _)
| Self::SameFile(_, _)
| Self::SameFile()
| Self::MissingDestination(_)
| Self::ExtraOperand(_) => 1,
}
@ -417,7 +417,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
ResolveMode::Logical,
)?;
if dst_abs == source_abs {
return Err(LnError::SameFile(dst.to_path_buf(), source.to_path_buf()).into());
return Err(LnError::SameFile().into());
}
}
if let Some(ref p) = backup_path {

View file

@ -622,7 +622,7 @@ fn test_backup_same_file() {
at.touch("file1");
ucmd.args(&["--backup", "file1", "./file1"])
.fails()
.stderr_contains("'file1' and './file1' are the same file");
.stderr_contains("n: failed to link 'file1' to './file1': Same file");
}
#[test]

View file

@ -180,4 +180,4 @@ sed -i -e "s~ sed -n \"1s/'\\\/'/'OPT'/p\" < err >> pat || framework_failure_~
sed -i -e "s/rcexp=1$/rcexp=2\n case \"\$prg\" in chcon|dir|runcon|vdir) return;; esac/" tests/misc/usage_vs_getopt.sh
# Update the GNU error message to match ours
sed -i -e "s/ln: 'f' and 'f' are the same file/ln: failed to link: 'f' and 'f' are the same file/g" tests/ln/hard-backup.sh
sed -i -e "s/ln: 'f' and 'f' are the same file/ln: failed to link 'f' to 'f': Same file/g" tests/ln/hard-backup.sh