ID: 35791
Updated by: sniper@php.net
Reported By: jgmtfia at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 5.1.1
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.1-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.1-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2005-12-24 01:07:44] judas dot iscariote at gmail dot com
File 'C' exists:
lrwxrwxrwx 1 1 2005-12-23 21:10 C -> A
Deleted 'C'
ls: C: No such file or directory
(PASS) PHP sees the file as deleted.
php -v
PHP 5.1.2RC2-dev (cli) (built: Dec 23 2005 17:37:05)
SUSE Linux 10 x86_64
------------------------------------------------------------------------
[2005-12-24 01:05:54] jgmtfia at gmail dot com
Interesting. How should I proceed?
------------------------------------------------------------------------
[2005-12-24 00:23:26] tony2001@php.net
That's what I get:
File 'C' exists:
rwxrwxrwx 1 1 2005-12-24 02:22 C -> A
Deleted 'C'
ls: C: No such file or directory
(PASS) PHP sees the file as deleted.
------------------------------------------------------------------------
[2005-12-23 22:16:07] jgmtfia at gmail dot com
Description:
------------
I have narrowed down a PHP problem. I can demonstrate it with
file_exists().
I have 2 files, A and B, and one symlink C that points to A.
-rw-r--r-- Dec 23 14:13 A
-rw-r--r-- Dec 23 14:13 B
lrwxr-xr-x Dec 23 14:13 C -> A
When I delete link C from PHP, and then clearstatcache(), file_exists()
returns true for link C. **It continues to do so until A is removed
from disk**. Using the Apache2 module, I do multiple page reloads and
only after some time has passed does PHP notice that link C has been
removed.
Not a big problem in general, however, if I do the following:
unlink("C");
symlink("B", "C");
file_get_contents("C");
**PHP still reads the contents of A**. Using the CLI version I have to
run the script again before the contents of B are read. In Apache I
need to reload multiple times.
I can reproduce this on linux kernels 2.6.10 and 2.6.14. On ext2 and
ext3 filesystems. The code below executes correctly (passes) with PHP
4.3.10 and fails on 5.1.0b3, 5.1.0 and 5.1.1.
Reproduce code:
---------------
<?php
touch A; ln -s A C;
$FILE = 'C';
$LS = "ls -log $FILE 2>&1";
clearstatcache();
if(!file_exists($FILE))
echo "$FILE link does not exist, cannot run test.\n";
echo "File '$FILE' exists:\n\t\t".$LS."\n";
if(!unlink($FILE)){
echo "Unable to delete '$FILE'\n\t\t".$LS."\n";
exit;
}
clearstatcache();
echo "Deleted '$FILE'\n\t\t".$LS."\n";
if(!file_exists($FILE)){
echo "(PASS) PHP sees the file as deleted.\n";
exit;
}
echo "(FAIL) File '$FILE' deleted as seen by OS. ";
echo "file_exists() still thinks it exists:\n\t\t".$LS."\n";
echo "Deleting 'A'\n";
unlink('A');
clearstatcache();
if(file_exists($FILE)){
echo "(FAIL) PHP still sees '$FILE' as
existing:\n\t\t".$LS."\n";
exit;
}
echo "(FAIL) PHP sees file as deleted only after link target
deleted.\n";
?>
Expected result:
----------------
~/x$ ./php-4.3.10-15 ./test.php
File 'C' exists:
lrwxr-xr-x 1 1 Dec 23 14:00 C -> A
Deleted 'C'
ls: C: No such file or directory
(PASS) PHP sees the file as deleted.
Actual result:
--------------
~/x$ ./php-5.1.1 ./test.php
File 'C' exists:
lrwxr-xr-x 1 1 Dec 23 14:02 C -> A
Deleted 'C'
ls: C: No such file or directory
(FAIL) File 'C' deleted as seen by OS. file_exists() still thinks it
exists:
ls: C: No such file or directory
Deleting 'A'
(FAIL) PHP sees file as deleted only after link target deleted.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35791&edit=1