Bug#844560: check for config file existence is wrong

Ian Jackson ijackson at chiark.greenend.org.uk
Fri Nov 18 16:08:32 UTC 2016


Hi.  Thanks for your attention to this mostly-cosmetic bug...

Mattia Rizzolo writes ("Re: Bug#844560: check for config file existence is wrong"):
> It does a regular
>     if [ -f "$RCFILE" ]; then
>         . "$RCFILE"

Yes.

> Which fails for non-regular files like /dev/null is.

Indeed.

> Do you mean that probably the message should takr into account that a reason
> for failure of that test could be something different than enonet?

Well, that would be one "fix".  It would stop the message from being
untruthful.  It has the virtue of being very easy.

But what I was suggesting was just to get rid of the separate test.  I
notice now that this is supposed to be a warning rather than an error,
so my suggestion wouldn't work.

> If that the problem it could prably be solved imho in a nicer way by nesting
> another if in the else branch to check for simple existence (by [ -e $file ])
> and print a proper message if the file exists but it's not regular, and keep
> the current message only for the real enoent case.

I think this way lies madness.  We already have a mechanism for
figuring out what went wrong: bash tries to open the file, and the
kernel figures out why it can't be opened, and tells bash an errno
value.  Trying to replicate this logic in your script will result in
an ever-increasing set of cases.

How about

  . "$RCFILE" || echo "W: $RCFILE could not be sourced" >&2

?

That would result in this:

mariner:~> bash -ec 'RCFILE=/dev/enoent; . "$RCFILE" || echo "W:
$RCFILE could not be sourced" >&2'
bash: /dev/enoent: No such file or directory
W: /dev/enoent could not be sourced
mariner:~>

Or you could just leave out the echo and do

  . "$RCFILE" ||:


If you don't like those suggestions, how about simply changing -f to
-e ?  That way /dev/null will just work.  And the existing message
about nonexistence would be truthful.

If the `.' fails for some reason other than nonexistence (eg, the file
exists but has wrong permissions, or it's actually a socket, or
something) then it's probably best to bomb out, anyway.

Regards,
Ian.

-- 
Ian Jackson <ijackson at chiark.greenend.org.uk>   These opinions are my own.

If I emailed you from an address @fyvzl.net or @evade.org.uk, that is
a private address which bypasses my fierce spamfilter.



More information about the Pbuilder-maint mailing list