Bug #71035 [Opn->Nab]: Rename() on Windows fails with read-only permissions on the target file

From: Date: Sat, 05 Dec 2015 01:48:54 +0000
Subject: Bug #71035 [Opn->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-197605@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:             Open
+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:

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.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (5 messages)

« previous php.bugs (#197605) next »