mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
cp: added -T/--no-target-directory flag
This commit is contained in:
parent
97bb134fc9
commit
cc57ce7699
1 changed files with 6 additions and 1 deletions
|
@ -36,6 +36,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
opts.optflag("h", "help", "display this help and exit");
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
opts.optflag("v", "version", "output version information and exit");
|
opts.optflag("v", "version", "output version information and exit");
|
||||||
opts.optopt("t", "target-directory", "copy all SOURCE arguments into DIRECTORY", "DEST");
|
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..]) {
|
let matches = match opts.parse(&args[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
@ -99,7 +100,7 @@ fn copy(matches: getopts::Matches) {
|
||||||
//the argument to the -t/--target-directory= options
|
//the argument to the -t/--target-directory= options
|
||||||
let path = Path::new(&dest_str);
|
let path = Path::new(&dest_str);
|
||||||
if !path.is_dir() && matches.opt_present("target-directory") {
|
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!()
|
panic!()
|
||||||
} else {
|
} else {
|
||||||
path
|
path
|
||||||
|
@ -108,6 +109,10 @@ fn copy(matches: getopts::Matches) {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(sources.len() >= 1);
|
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 {
|
if sources.len() == 1 {
|
||||||
let source = Path::new(&sources[0]);
|
let source = Path::new(&sources[0]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue