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

yary not.com at gmail.com
Fri Jun 6 17:30:29 PDT 2008


On Fri, Jun 6, 2008 at 2:13 PM, Asheesh Laroia <asheesh at asheesh.org> wrote:
...
>
> Anyway, I agree that this behavior in Perl is broken - what's the point of
> a 'read' test whose return value must be double-checked?!

You'll find it's not just perl- C, python, php, etc will all do the
same, they all use the same system calls. The operating system looks
at the permission bits (and access control list, if any) and returns
its pronouncement based on the effective user/group ID. The OS doesn't
know that some underlying filesystem will chose to disregard or change
the user ID... that particular call "stat" predates the invention of
NFS...

Another time these calls may "fail" is when checking for writeability
of files on a volume mounted read-only.

One could argue that there needs to be a better OS level interface for
testing files than 'stat'- which basically returns the directory
entry, ie owner/group of file + permissions + access/change times,
etc- and lets the caller decide readability, etc from that. Would be
nice if you could ask the OS "can this user/group read/write/execute
this file", have the OS ask the filesystem... which happens when you
use "open", and then read/write/execute- so always check those return
values!


More information about the SanFrancisco-pm mailing list