Bug #71035 [Nab]: Rename() on Windows fails with read-only permissions on the target file
| From: | requinix@php.net | Date: | Wed, 09 Dec 2015 19:30:05 +0000 |
| Subject: | Bug #71035 [Nab]: Rename() on Windows fails with read-only permissions on the target file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197746@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71035&edit=1
ID: 71035
Updated by: requinix@php.net
Reported by: info at mikekeran dot com
Summary: Rename() on Windows fails with read-only permissions
on the target file
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows
PHP Version: 5.5.30
Block user comment: N
Private report: N
New Comment:
Normalizing could make sense if there was an accepted standard for how it should work. But there
isn't.
There are many things that differ across platforms and that a developer should be aware of. This is
one of them.
Previous Comments:
------------------------------------------------------------------------
[2015-12-09 19:02:02] info at mikekeran dot com
Thank you for the quick reply, requinix@php.net.
I understand the differences in the underlying file permissions, however I expected PHP to normalize
that. Couldn't rename() chmod 0666 the file before overwriting it? Yes, I realize that I can do
that in my script, but it seems to me that this level of abstraction should happen at the language
level.
Thoughts?
------------------------------------------------------------------------
[2015-12-05 01:48:53] requinix@php.net
Windows permission system (including the read-only attribute) does not work like Unix's
permission system. Read-only prevents changes to the file, and that includes replacing the file with
something else.
Try it yourself without PHP: make a file, mark it read-only, then try to copy another file onto it.
------------------------------------------------------------------------
[2015-12-04 22:49:00] info at mikekeran dot com
Description:
------------
When using rename to replace an existing file, PHP on Windows incorrectly gives an access denied if
the target file is read-only (0444):
An access denied error should only be given if the target file's directory permissions should
keep the current user from writing to that location. Linux (tested on Ubuntu 14.04) works as
expected.
Test script:
---------------
<?php
file_put_contents('./test.txt', 'test data');
file_put_contents('./newtest.txt', 'new test data');
chmod('test.txt', 0666);
rename('newtest.txt', 'test.txt');
print "test.txt is now: " . file_get_contents('./test.txt') . "\n";
file_put_contents('./test.txt', 'test data');
file_put_contents('./newtest.txt', 'new test data');
chmod('test.txt', 0444);
rename('newtest.txt', 'test.txt');
print "test.txt is now: " . file_get_contents('./test.txt') . "\n";
Expected result:
----------------
test.txt is now: new test data
test.txt is now: new test data
Actual result:
--------------
test.txt is now: new test data
Warning: rename(newtest.txt,test.txt): Access is denied. (code: 5) in
C:\Users\Mike\Documents\dev\sandbox\sandbox.php on line 13
test.txt is now: test data
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71035&edit=1