[sf-perl] Bug in perl (or does -r not do what I think?)

Steve Fink sphink at gmail.com
Fri Jun 6 17:28:05 PDT 2008

> dan at dbdb$ sudo perl -le 'print "lies" if -r shift' somefile.png
> lies
> dan at dbdb$ sudo file somefile.png
> couldn't open file
> somefile.png: regular file, no read permission
> Is perl just assuming that if I'm root I can always read the file, even
> though the permissions say that's wrong?

Does it do any better with:

  sudo perl -Mfiletest=access -le 'print "lies" if -r shift' somefile.png

? There's a good chance it still won't work:

       access() may not work correctly on NFS file systems  with  UID  mapping
       enabled,  because UID mapping is done on the server and hidden from the
       client, which checks permissions.

Also... what are you doing it for? There are a number of legitimate
uses, but it's also a common race condition -- just because something
is readable at the moment you checked doesn't mean that it'll still be
readable when you try to read it. So if you really depend on it being
correct, then you'll have to just try to do the operation and check
failure then.

More information about the SanFrancisco-pm mailing list