diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 7d48d42be..b3255dd9b 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -36,6 +36,7 @@ pub fn uumain(args: Vec) -> i32 { opts.optflag("h", "help", "display this help and exit"); opts.optflag("v", "version", "output version information and exit"); opts.optopt("t", "target-directory", "copy all SOURCE arguments into DIRECTORY", "DEST"); + opts.optflag("T", "no-target-directory", "Treat DEST as a regular file and not a directory"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -99,7 +100,7 @@ fn copy(matches: getopts::Matches) { //the argument to the -t/--target-directory= options let path = Path::new(&dest_str); if !path.is_dir() && matches.opt_present("target-directory") { - show_error!("Argument to -t/--target-directory must be a directory"); + show_error!("Target {} is not a directory", matches.opt_str("target-directory").unwrap()); panic!() } else { path @@ -108,6 +109,10 @@ fn copy(matches: getopts::Matches) { }; assert!(sources.len() >= 1); + if matches.opt_present("no-target-directory") && dest.is_dir() { + show_error!("Can't overwrite directory {} with non-directory", dest.display()); + panic!() + } if sources.len() == 1 { let source = Path::new(&sources[0]);