mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
add to makefile, basic mkdir functionality done
This commit is contained in:
parent
512ae48161
commit
d0c2896b16
2 changed files with 39 additions and 16 deletions
1
Makefile
1
Makefile
|
@ -13,6 +13,7 @@ PROGS := \
|
||||||
echo \
|
echo \
|
||||||
env \
|
env \
|
||||||
false \
|
false \
|
||||||
|
mkdir \
|
||||||
printenv \
|
printenv \
|
||||||
pwd \
|
pwd \
|
||||||
rmdir \
|
rmdir \
|
||||||
|
|
|
@ -14,25 +14,18 @@ extern mod extra;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::io::stderr;
|
use std::io::stderr;
|
||||||
use extra::getopts::groups;
|
use extra::getopts::groups;
|
||||||
use std::io::fs::mkdir;
|
use std::io::fs;
|
||||||
use std::path;
|
|
||||||
|
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn print_help(opts: &[groups::OptGroup]) {
|
|
||||||
println!("mkdir v{} - make a new directory with the given path", VERSION);
|
|
||||||
println("");
|
|
||||||
println("Usage:");
|
|
||||||
print(groups::usage("Create the given DIRECTORY(ies)" +
|
|
||||||
" if they do not exist", opts));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: ~[~str] = os::args();
|
let args: ~[~str] = os::args();
|
||||||
let program: ~str = args[0].clone();
|
|
||||||
|
|
||||||
let opts: ~[groups::OptGroup] = ~[
|
let opts: ~[groups::OptGroup] = ~[
|
||||||
|
// Linux-specific options
|
||||||
// groups::optflag("m", "mode", "set file mode"),
|
// groups::optflag("m", "mode", "set file mode"),
|
||||||
|
// groups::optflag("Z", "context", "set SELinux secutiry context" +
|
||||||
|
// " of each created directory to CTX"),
|
||||||
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"),
|
||||||
|
@ -59,11 +52,40 @@ fn main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parents: bool = matches.opt_present("parents");
|
let mk_parents: bool = matches.opt_present("parents");
|
||||||
mkdir(parents);
|
let dirs: ~[~str] = matches.free;
|
||||||
|
mkdir(dirs, mk_parents);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkdir(mk_parents: bool) {
|
fn print_help(opts: &[groups::OptGroup]) {
|
||||||
|
println!("mkdir v{} - make a new directory with the given path", VERSION);
|
||||||
|
println("");
|
||||||
|
println("Usage:");
|
||||||
|
print(groups::usage("Create the given DIRECTORY(ies)" +
|
||||||
|
" if they do not exist", opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* std::libc currently does not provide bindings for any bits
|
||||||
|
besides user bits, so might as well use octal for now.
|
||||||
|
See 'std::io::FilePermission',
|
||||||
|
'std::libc::consts::os::posix88' for future updates */
|
||||||
|
fn mkdir(dirs: ~[~str], mk_parents: bool) {
|
||||||
|
let default: u32 = 0o755;
|
||||||
|
|
||||||
|
for dir in dirs.iter() {
|
||||||
|
let path = Path::new((*dir).clone());
|
||||||
|
// Recursively create parent dirs as needed
|
||||||
|
if mk_parents {
|
||||||
|
match path.dirname_str() {
|
||||||
|
Some(p) => if p != "." {
|
||||||
|
mkdir(~[p.into_owned()], mk_parents)
|
||||||
|
},
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !path.exists() {
|
||||||
|
println(*dir);
|
||||||
|
fs::mkdir(&path, default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue