[Toybox] mkdir -p is subtle.

Rob Landley rob at landley.net
Wed Mar 7 18:02:55 PST 2012


If you "mkdir -p one/two/three" and all three of those already exist,
and are directories, it should succeed without error.  So -EEXIST on the
last -p directory is not an error.  (This broke the aboriginal linux build.)

But: if you "mkdir -p one/two" and one is a directory but two is a file,
both stages will fail with -EEXIST and you can't distinguish the file
from directory unless you special case the check for this, and stat the
last entry you created in the eexist case.

Except that if you _do_ a stat, it zaps the errno state so you're not
naturally reporting the right error.

Oh, and this one's fun:

  mkdir one
  ln -s . one/three
  mkdir -p one/three/three

It's perfectly happy with that.  Not an error.

I should really do a test suite for mkdir...

Rob

P.S.  The fact that gcc just accidentally _accepted_:

  for (s=top; ;s++) {
     blah blah blah;
  } while (i++);

Sort of fills me with dread at the cthulian horror that must be under
the hood of this thing...


More information about the Toybox mailing list