At 14:50 16/01/01 +0200, Peter Pentchev wrote:
>As somebody already pointed out, there *is* a dirname(3) function, and even
>a dirname(1) cmdline utility to invoke it.
oops. I'll need to stay current:)
>In a followup to Alfred's mkdir(1) commit, I sent a sample implementation
>of a direxname() function, which calls dirname(3) in a loop, and returns
>the longest existing path component. I'll get back to him shortly
>with a patch to mkdir(1) using direxname() to report a meaningful error
>message, something like "Cannot create /exists/nonex/foo/bar, nonexistent
>path components after /exists". In the meantime, attached is my first
>shot at direxname() implementation, using dirname(3)'s static buffer.
I'm not convinced you really need to check which is the "largest" parent that
exists.
if /a doesn't exist, and I do a mkdir /a/b/c/d, just a "/a/b/c does not
exist" is
far sufficient.
For me, if you ignore permissions and the like, the condition
to create a directory is that its parent exists, whatever are his
grand-parents.
after the error is shown, one will anyway check which dirs exist.
doing the stat() on all those just consumes time, with few benefits.
on an NFS mounted fs, this would be just annoyiing sometimes.
now if you really insist, I'd suggest doing the stat the other way: check
the root,
then its children, then the children of the latter... like in mkdir -p.
at last, note that there might be race conditions while you stat(). but
there is hardly
a way to avoid'em. at least, a single stat() reduces the window of opportunity.
regards,
mouss
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message