diff options
author | Rob Landley <rob@landley.net> | 2013-12-18 10:20:16 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-12-18 10:20:16 -0600 |
commit | ed9eac3967ed88262293aa395744194f8be294b0 (patch) | |
tree | 3d5e4ab9ce2cca36218bd8482785fab38188aebc | |
parent | 4f20b9628bff272c504b6bf2c7c71619f7337022 (diff) | |
download | toybox-ed9eac3967ed88262293aa395744194f8be294b0.tar.gz |
Ashwini Sharma added -v, I tweaked it a bit and added a couple test suite entries.
-rw-r--r-- | scripts/test/mkdir.test | 6 | ||||
-rw-r--r-- | toys/posix/mkdir.c | 15 |
2 files changed, 15 insertions, 6 deletions
diff --git a/scripts/test/mkdir.test b/scripts/test/mkdir.test index cbd425d4..583b4c0d 100644 --- a/scripts/test/mkdir.test +++ b/scripts/test/mkdir.test @@ -58,3 +58,9 @@ testing "mkdir -p -m 777 (377 umask)" \ "700\n777\n" "" "" umask 002 rm -rf one + +testing "mkdir -vp" "mkdir -vp walrus 2>&1" \ + "mkdir: created directory 'walrus'\n" "" "" + +testing "mkdir -vp exists" "mkdir -vp walrus 2>&1" \ + "" "" "" diff --git a/toys/posix/mkdir.c b/toys/posix/mkdir.c index 202eaa79..00946389 100644 --- a/toys/posix/mkdir.c +++ b/toys/posix/mkdir.c @@ -4,17 +4,18 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/mkdir.html -USE_MKDIR(NEWTOY(mkdir, "<1pm:", TOYFLAG_BIN|TOYFLAG_UMASK)) +USE_MKDIR(NEWTOY(mkdir, "<1vpm:", TOYFLAG_BIN|TOYFLAG_UMASK)) config MKDIR bool "mkdir" default y help - usage: mkdir [-p] [-m mode] [dirname...] + usage: mkdir [-vp] [-m mode] [dirname...] Create one or more directories. + -m set permissions of directory to mode. -p make parent directories as needed. - -m set permissions of directory to mode. + -v verbose */ #define FOR_mkdir @@ -55,9 +56,11 @@ static int do_mkdir(char *dir) if (save == '/') mode |= 0300; else if (toys.optflags&FLAG_m) mode = TT.mode; - if (mkdir(dir, mode)<0 && (!(toys.optflags&FLAG_p) || errno != EEXIST)) - return 1; - + if (mkdir(dir, mode)) { + if (!(toys.optflags&FLAG_p) || errno != EEXIST) return 1; + } else if (toys.optflags&FLAG_v) + fprintf(stderr, "%s: created directory '%s'\n", toys.which->name, dir); + if (!(*s = save)) break; } |