bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mkdir enhancement/bug? - mode & parents


From: Bill McGonigle
Subject: mkdir enhancement/bug? - mode & parents
Date: Wed, 20 Aug 2003 19:03:19 -0400

Hi,

I assumed this would be an FAQ, but I didn't find it on the FAQ or in the archives.

If I do:
   mkdir -m 777 -p a/b/c/d/e/

I would expect mkdir to make a, b, c, d, and e for me, set to 777. Actually, it sets a,b,c, and d to 755, the value from my umask, and e to 777. I don't see an easy way to do what I expect, besides following up the mkdir with a chmod -R. The info page defines this behavior correctly.

The POSIX spec for -p:
   mkdir -p -m $(umask -S),u+wx $(dirname dir) && mkdir [-m mode] dir
   http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html

defines the behavior of mkdir -p in terms of mkdir -p, implying recursion, and the base case in the recursion has a way out as -p no longer applies.

If I run the specification explicity in a bash shell, expanded:
  mkdir -p -m u=rwx,g=rx,o=rx,u+wx a/b/c/d && mkdir -m 777 a/b/c/d/e
I get the results as the info page specifies. That's good, but it's self-defined as it depends on the behavior of mkdir -p.

But if I spell out the recursion, with -p defined as the && of the two expressions, one would get, at each recursive step:

mkdir -p -m u=rwx,g=rx,o=rx,u+wx a/b/c/d && mkdir -m 777 a/b/c/d/e
  mkdir -p -m u=rwx,g=rx,o=rx,u+wx a/b/c && mkdir -m 777 a/b/c/d
    mkdir -p -m u=rwx,g=rx,o=rx,u+wx a/b && mkdir -m 777 a/b/c
      mkdir -p -m u=rwx,g=rx,o=rx,u+wx a && mkdir -m 777 a/b

because of how basename works. This would leave my permissions on a/b/c/d/e as 755,777,777,777,777

If someone wanted to argue that the base case for -p with no children was to do nothing, and let the right side of the expression prevail, I might buy it, in which case I'd get all 777's. If one agrees that my interpretation is correct, then it's not a stretch to assume this was the intention, since it produces the more useful result.

Differently, mkdir seems to define -p as the recursion of the left expression, then &&'ing it with the right, but I think the spec is defining mkdir as the && of the two expressions, so both should be evaluated in each step.

I understand changing mkdir's behavior would tick off alot of people. I bring it up as a point of discussion, to point out how I got here, that perhaps the POSIX spec isn't as clear as it needs to be, and that people might expect different behaviors. Of course, if someone can point out how I'm be misinterpreting the spec, that would be great too.

So, after all that rambling, what would be useful would be an option to mkdir which would eliminate the need for the follow-up chown call and disambiguate the spec interpretation, say something like --chown-parents.

Thanks for listening,
-Bill





reply via email to

[Prev in Thread] Current Thread [Next in Thread]