ID:               35791
 User updated by:  jgmtfia at gmail dot com
 Reported By:      jgmtfia at gmail dot com
-Status:           Feedback
+Status:           Open
 Bug Type:         Filesystem function related
 Operating System: Linux
 PHP Version:      5.1.1
 New Comment:

Interesting.  How should I proceed?


Previous Comments:
------------------------------------------------------------------------

[2005-12-24 00:23:26] [EMAIL PROTECTED]

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

Reply via email to