Subject: | atomic write to unwritable file |
Date: | Sun, 07 Apr 2019 11:22:39 +1000 |
To: | bug-File-Slurp [...] rt.cpan.org |
From: | Kevin Ryde <user42_kevin [...] yahoo.com.au> |
If a file does not have write permission, write_file() gets an error on
attempting to rewrite it. But with the atomic option, it is rewritten
successfully. Eg.
use File::Slurp;
system 'rm -f /tmp/unwritable';
system 'echo hello >/tmp/unwritable';
system 'chmod 000 /tmp/unwritable';
write_file('/tmp/unwritable', {atomic => 1}, "goodbye");
# succeeds
In the interests of consistency, it'd be good for atomic to behave the
same as ordinary in respect of file permissions.
I'd think an error would be right. Perhaps atomic would test writable
before starting the tempfile etc. Is faccessat() AT_EACCESS the closest
test of sysopen O_WRONLY ability? Does "use filetest 'access'" give
that to -w, or is that only plain access() going on real uid?