mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cp: added -T/--no-target-directory flag
This commit is contained in:
+6
-1
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user