Bug #72364 [Com]: SplFileInfo->isFile() returns true for symlinks
| From: | kevin dot boyd at gmail dot com | Date: | Wed, 15 Jun 2016 21:48:11 +0000 |
| Subject: | Bug #72364 [Com]: SplFileInfo->isFile() returns true for symlinks | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201667@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72364&edit=1
ID: 72364
Comment by: kevin dot boyd at gmail dot com
Reported by: kevin dot boyd at gmail dot com
Summary: SplFileInfo->isFile() returns true for symlinks
Status: Verified
Type: Bug
Package: SPL related
Operating System: OS X and Linux
PHP Version: 5.5.36
Block user comment: N
Private report: N
New Comment:
> Well, in this case I'd rather fix the documentation to match the
> actual behavior. That avoids any BC break, and there is already
> SplFileInfo::isLink().
This certainly seems like the pragmatic approach. I wouldn't want
to change it in a way that makes it behave differently than it
does in other C-based implementations. Still, I wonder if the
ordering of the cases in the switch statement is done some other
way in other libraries - such as with link first. That could prove
to be the difference, if the bit-shifted value was matching both
file and link.
Previous Comments:
------------------------------------------------------------------------
[2016-06-09 18:11:14] cmb@php.net
I can confirm the issue for Windows (PHP 7.0.7).
> Theoretically, if the "case FS_IS_FILE:" block were modified in
> ext/standard/filestat.c (around line 991), that could
> potentially bring the behaviour in line with what has been
> documented.
Well, in this case I'd rather fix the documentation to match the
actual behavior. That avoids any BC break, and there is already
SplFileInfo::isLink().
------------------------------------------------------------------------
[2016-06-09 06:25:35] kevin dot boyd at gmail dot com
I've done some poking around and found that this appears to be the way lstat() behaves in C -
either that or there's some funky bitshifting going on that I don't fully grok.
Theoretically, if the "case FS_IS_FILE:" block were modified in ext/standard/filestat.c
(around line 991), that could potentially bring the behaviour in line with what has been documented.
Current logic:
RETURN_BOOL(S_ISREG(ssb.sb.st_mode));
Proposed change:
RETURN_BOOL(S_ISREG(ssb.sb.st_mode) && !S_ISLNK(ssb.sb.st_mode));
I don't know what the potential ramifications of this change might be.
------------------------------------------------------------------------
[2016-06-08 21:59:59] kevin dot boyd at gmail dot com
Description:
------------
The documentation for ->isFile() says that it should not return true for links, but I was not
able to observe this behaviour.
http://php.net/manual/en/splfileinfo.isfile.php
(This was encountered on PHP 5.5.35 and 5.3.10 on OS X and Ubuntu 12.04.5)
Test script:
---------------
<?php
touch('test.txt');
symlink('test.txt', 'link.txt');
$file = new SplFileInfo('link.txt');
if ($file->isFile()) {
echo "Expected isFile to return false, but it returned true!\n";
}
unlink('test.txt');
unlink('link.txt');
Expected result:
----------------
I expect it to return no output. ->isFile() should return false for symbolic links.
Actual result:
--------------
$ php repro.php
Expected isFile to return false, but it returned true!
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72364&edit=1