mirror of
https://github.com/uutils/coreutils
synced 2024-09-16 06:21:12 +00:00
remove unneeded typing, swap cat and mkdir
This commit is contained in:
parent
f60799ffc9
commit
9cd301f653
2
Makefile
2
Makefile
|
@ -30,8 +30,8 @@ EXES := \
|
||||||
|
|
||||||
# Programs with usable tests
|
# Programs with usable tests
|
||||||
TEST_PROGS := \
|
TEST_PROGS := \
|
||||||
mkdir \
|
|
||||||
cat \
|
cat \
|
||||||
|
mkdir \
|
||||||
|
|
||||||
TEST ?= $(TEST_PROGS)
|
TEST ?= $(TEST_PROGS)
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ static VERSION: &'static str = "1.0.0";
|
||||||
* Handles option parsing
|
* Handles option parsing
|
||||||
*/
|
*/
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: ~[~str] = os::args();
|
let args = os::args();
|
||||||
|
|
||||||
let opts: ~[groups::OptGroup] = ~[
|
let opts = ~[
|
||||||
// Linux-specific options, not implemented
|
// Linux-specific options, not implemented
|
||||||
// groups::optflag("Z", "context", "set SELinux secutiry context" +
|
// groups::optflag("Z", "context", "set SELinux secutiry context" +
|
||||||
// " of each created directory to CTX"),
|
// " of each created directory to CTX"),
|
||||||
|
@ -32,9 +32,9 @@ fn main() {
|
||||||
groups::optflag("p", "parents", "make parent directories as needed"),
|
groups::optflag("p", "parents", "make parent directories as needed"),
|
||||||
groups::optflag("v", "verbose",
|
groups::optflag("v", "verbose",
|
||||||
"print a message for each printed directory"),
|
"print a message for each printed directory"),
|
||||||
groups::optflag("", "help", "display this help"),
|
groups::optflag("h", "help", "display this help"),
|
||||||
groups::optflag("", "version", "display this version")
|
groups::optflag("", "version", "display this version")
|
||||||
];
|
];
|
||||||
|
|
||||||
let matches = match groups::getopts(args.tail(), opts) {
|
let matches = match groups::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
@ -54,18 +54,14 @@ fn main() {
|
||||||
println("mkdir v" + VERSION);
|
println("mkdir v" + VERSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut verbose_flag: bool = false;
|
let verbose_flag = matches.opt_present("verbose");
|
||||||
if matches.opt_present("verbose") {
|
let mk_parents = matches.opt_present("parents");
|
||||||
verbose_flag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mk_parents: bool = matches.opt_present("parents");
|
|
||||||
|
|
||||||
// Translate a ~str in octal form to u32, default to 755
|
// Translate a ~str in octal form to u32, default to 755
|
||||||
// Not tested on Windows
|
// Not tested on Windows
|
||||||
let mode_match = matches.opts_str(&[~"mode"]);
|
let mode_match = matches.opts_str(&[~"mode"]);
|
||||||
let mode: u32 = if mode_match.is_some() {
|
let mode: u32 = if mode_match.is_some() {
|
||||||
let m: ~str = mode_match.unwrap();
|
let m = mode_match.unwrap();
|
||||||
let res = strconv::from_str_common(m, 8, false, false, false,
|
let res = strconv::from_str_common(m, 8, false, false, false,
|
||||||
strconv::ExpNone,
|
strconv::ExpNone,
|
||||||
false, false);
|
false, false);
|
||||||
|
@ -81,7 +77,7 @@ fn main() {
|
||||||
0o755
|
0o755
|
||||||
};
|
};
|
||||||
|
|
||||||
let dirs: ~[~str] = matches.free;
|
let dirs = matches.free;
|
||||||
exec(dirs, mk_parents, mode, verbose_flag);
|
exec(dirs, mk_parents, mode, verbose_flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,17 +118,17 @@ fn exec(dirs: ~[~str], mk_parents: bool, mode: u32, verbose: bool) {
|
||||||
let path = Path::new((*dir).clone());
|
let path = Path::new((*dir).clone());
|
||||||
// Determine if parent directory to the one to
|
// Determine if parent directory to the one to
|
||||||
// be created exists
|
// be created exists
|
||||||
let parent: &str = match path.dirname_str() {
|
let parent = match path.dirname_str() {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => ""
|
None => ""
|
||||||
};
|
};
|
||||||
let parent_exists:bool = Path::new(parent).exists();
|
let parent_exists = Path::new(parent).exists();
|
||||||
if parent_exists && !path.exists() {
|
if parent_exists && !path.exists() {
|
||||||
// if mkdir failed return
|
// if mkdir failed return
|
||||||
if !mkdir(&path, mode) {return;}
|
if !mkdir(&path, mode) {return;}
|
||||||
if verbose {println(*dir);}
|
if verbose {println(*dir);}
|
||||||
} else {
|
} else {
|
||||||
let mut error_msg: ~str = ~"";
|
let mut error_msg = ~"";
|
||||||
if !parent_exists {
|
if !parent_exists {
|
||||||
error_msg.push_str("Error: parent directory '");
|
error_msg.push_str("Error: parent directory '");
|
||||||
error_msg.push_str(parent);
|
error_msg.push_str(parent);
|
||||||
|
|
Loading…
Reference in a new issue