Bug #71035 [NEW]: Rename() on Windows fails with read-only permissions on the target file
| From: | info at mikekeran dot com | Date: | Fri, 04 Dec 2015 22:49:03 +0000 |
| Subject: | Bug #71035 [NEW]: Rename() on Windows fails with read-only permissions on the target file | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-197601@lists.php.net to get a copy of this message | ||
From: info at mikekeran dot com
Operating system: Windows
PHP version: 5.5.30
Package: *General Issues
Bug Type: Bug
Bug description:Rename() on Windows fails with read-only permissions on the target file
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 bug report at https://bugs.php.net/bug.php?id=71035&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71035&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71035&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71035&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71035&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71035&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71035&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71035&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71035&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71035&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71035&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71035&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71035&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71035&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71035&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71035&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71035&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71035&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71035&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71035&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71035&r=mysqlcfg