AlPaton has asked for the wisdom of the Perl Monks concerning the following question:

Perl 5.8 on Solaris or Linux. The file status operators (-w -r -e) do not 'tickle' the filesystem automounter, so -w for example returns FALSE on a writable directory that is currently an unmounted filesystem. Is this a bug, or are we supposed to work around that? Is it the same on later versions?

Replies are listed 'Best First'.
Re: automounted directory status
by DrHyde (Prior) on Jan 31, 2014 at 11:58 UTC

    On perl 5.14.2 (the only version I've got on this 'ere Linux machine, but I assume it's the same on 5.8), -w and friends boil down to stat(2) calls:

    $ strace perl -e '-w "/etc"' ... stat("/etc", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 ...

    Perl doesn't know about filesystems and automount, it just relies on the OS to Do The Right Thing. If you write a little snippet of C code that just stat()s a directory, then I expect you'll find that it behaves the same.

Re: automounted directory status
by marto (Cardinal) on Jan 31, 2014 at 10:44 UTC

    If file systems aren't currently mounted, then there's nothing to check. If you ls this directory does it return anything for directories which are not currently in use? Can you force the automount, or run such checks on the server providing these mounts?

Re: automounted directory status
by trippledubs (Deacon) on Jan 31, 2014 at 13:48 UTC
    I tested -w on automounting directores in Solaris, Perl 5.8 and they automounted. Maybe something else is wrong.
      Can you post your evidence like this please: # ls -ld /u1/tmpint # is it mounted? dr-xr-xr-x 1 root root 1 Jan 30 11:33 /u1/tmpint/ # perl -e 'if ( -w "/u1/tmpint" ) { print "TRUE\n" } else { print "FALSE\n" }' FALSE # ls -ld /u1/tmpint # is it mounted? drwxrwxr-x 2506 root users 4365 Jan 31 10:27 /u1/tmpint/
        [root@server:/home] ls [root@server:/home] perl -e 'print -w "/home/shared"' 1[root@server:/home] ls shared [root@server:/home] umount shared [root@server:/home]
Re: automounted directory status
by Anonymous Monk on Jan 31, 2014 at 17:15 UTC
    The automounter probably is not activated if you stat the mountpoint; you need to stat a non-existent file inside the mountpoint.
      That definitely appears to be the case. My point is that, perhaps perl should answer the question asked, i.e. is the object (directory in this case) writable. The answer should not be OS dependant, ie. different if it is an unmounted but automountable directory. I just want to know if I can write a file to it, which I can in this case, mounted or not. I should not have to write code that works around the issues raised by automounted filesystems.

        But it *is* answering the question asked. 'Is /mnt/blahblah' writeable now' is not the same question as 'is /mnt/blahblah writeable after it has been autommounted'. You are asking 'is it writeable now'. The canonical way of asking that question is a stat(2) call. As I demonstrated, that is what perl does. It's what your shell probably does too - mine certainly does:

        $ strace sh -c "if [ -w /etc ]; then echo Writeable; fi" ... stat("/etc", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0 ...

        Which clearly shows that perl is Doing The Right Thing by using stat(2) to check whether the directory is writeable.