just another one of my rumblings

Denys Vlasenko vda.linux at googlemail.com
Fri Apr 25 22:59:39 UTC 2008


On Friday 25 April 2008 21:49, Paul Smith wrote:
> > > +       mkdir -p ".tmpdir.$applet" || return 1
> > >
> > > mkdir may report error when dir already exist - which
> > > should be ignored.
> > 
> > Ok.  I've sinned :(
> >         mkdir -p ".tmpdir.$applet" || :
> > then?
> 
> As someone mentioned, this is not necessary and in fact, is arguably
> incorrect.  mkdir -p will NOT print any message and will not exit with
> an error code if the directory already exists.

But this require casual reader to stop and think "will it work correctly
if directory already exists? Hmmm... I need to check manpage".

> It WILL print a message and will exit with an error code if it can't
> create the directory for other reasons, such as permissions etc.

My point is that "mkdir -p foo" works, and needs no fixing.

If it ain't broke, don't fix it. Not a hard rule, but
that patch was violating it a lot.

> You don't want to ignore those other reasons, so I think you SHOULD
> continue to catch errors from mkdir -p.

In this case "mkdir -p foo" is immediately followed by "cd foo || exit 1",
and that reliably catches all problems with directory creation.

Again: the code was ok, no need to fix that particular place.
--
vda



More information about the busybox mailing list