1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cp: added -T/--no-target-directory flag

This commit is contained in:
Jeremy Neptune 2016-07-15 14:08:04 -04:00
parent 97bb134fc9
commit cc57ce7699
No known key found for this signature in database
GPG key ID: C09EDE50FDEF1BB7

View file

@ -36,6 +36,7 @@ pub fn uumain(args: Vec<String>) -> 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]);