Perl: checking that the file ** is actually ** writable, as opposed to checking file permissions

Say I have a file / var / tmp / filename

In perl, I write the following snippet

#!/usr/bin/env perl
use strict;
use warnings;

if (-W /var/tmp/filename)
{
...
}

exit;

Will the -W and -w functions ( http://perldoc.perl.org/functions/-X.html ) verify that the file can actually be written or checked only that the files are allowed to allow ?

I ask that I write a script that receives a cookie from the server.

script cookie , cookie , . , cookie , .

+4
3

, , . , /proc/mounts ro, grep ro .

, /proc, .

, mount .

- , File:: Temp.

+4

, -X , . , .

http://perldoc.perl.org/functions/-X.html:

-r, -R, -w, -W, -x -X , uids gid . , , : , , ( ), . , - , .

loopback- (Ubuntu 16.04), -W , .

touch:

$ touch /media/MountPoint/testfile
touch: cannot touch '/media/MountPoint/testfile': Read-only file system

backtics:

unless (length `touch $filename`) 
{
    print "Can write\n";
}
+3

Yes. You can also do something like below:

if (-r $file && -w $file) {
    # file exists, I can read and write it
}
0
source

Source: https://habr.com/ru/post/1664868/


All Articles