[hackers] [sbase] Fix mkdir -p and allow -m to be specified along with -p || sin
commit d6885987e5f8fabd486d94d649206d0c34fc5ef0
Author: sin <sin_AT_2f30.org>
Date: Mon Apr 20 16:12:36 2015 +0100
Fix mkdir -p and allow -m to be specified along with -p
The mkdirp() function would not create the entire path but it just
happened to work because of the extra mkdir in the main loop.
diff --git a/mkdir.c b/mkdir.c
index b0d8bc2..1b0bf91 100644
--- a/mkdir.c
+++ b/mkdir.c
_AT_@ -11,17 +11,21 @@ mkdirp(char *path)
{
char *p;
- for (p = path + (*path == '/'); *p; p++) {
+ for (p = path; *p; p++) {
if (*p != '/')
continue;
*p = '\0';
if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST) {
weprintf("mkdir %s:", path);
+ *p = '/';
return -1;
}
*p = '/';
}
-
+ if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST) {
+ weprintf("mkdir %s:", path);
+ return -1;
+ }
return 0;
}
_AT_@ -54,14 +58,15 @@ main(int argc, char *argv[])
usage();
for (; *argv; argc--, argv++) {
- if (pflag && mkdirp(*argv) < 0) {
- ret = 1;
- } else if (mkdir(*argv, S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- if (!(pflag && errno == EEXIST)) {
+ if (pflag) {
+ if (mkdirp(*argv) < 0)
+ ret = 1;
+ } else if (mkdir(*argv, S_IRWXU | S_IRWXG | S_IRWXO) < 0 &&
+ errno != EEXIST) {
weprintf("mkdir %s:", *argv);
ret = 1;
- }
- } else if (mflag && chmod(*argv, mode) < 0) {
+ }
+ if (mflag && chmod(*argv, mode) < 0) {
weprintf("chmod %s:", *argv);
ret = 1;
}
Received on Mon Apr 20 2015 - 17:36:08 CEST
This archive was generated by hypermail 2.3.0
: Mon Apr 20 2015 - 17:48:11 CEST