From 3e6ac628bc9603f23a89bf509c68e3777a1a2e29 Mon Sep 17 00:00:00 2001 From: Nathan Ross Date: Sat, 20 Feb 2016 17:32:15 -0500 Subject: [PATCH] link: normalize file-not-found error message across platforms --- src/link/link.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/link/link.rs b/src/link/link.rs index 863c9814e..9c8a5e598 100644 --- a/src/link/link.rs +++ b/src/link/link.rs @@ -17,10 +17,18 @@ extern crate uucore; use std::fs::hard_link; use std::io::Write; use std::path::Path; +use std::io::Error; static NAME: &'static str = "link"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +pub fn normalize_error_message(e: Error) -> String { + match e.raw_os_error() { + Some(2) => { String::from("No such file or directory (os error 2)") } + _ => { format!("{}", e) } + } +} + pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); @@ -58,7 +66,7 @@ Create a link named FILE2 to FILE1.", NAME, VERSION); match hard_link(old, new) { Ok(_) => 0, Err(err) => { - show_error!("{}", err); + show_error!("{}",normalize_error_message(err)); 1 } }