Bug #65697 [Com]: is_link not working with windows junctions
[email protected] ("finitor at gmail dot com")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=65697&edit=1
ID: 65697
Comment by: finitor at gmail dot com
Reported by: giunta dot gaetano at gmail dot com
Summary: is_link not working with windows junctions
Status: Not a bug
Type: Bug
Package: *Directory/Filesystem functions
Operating System: win7 64bit
PHP Version: 5.4.19
Block user comment: N
Private report: N
New Comment:
<?php
$link = symlink('a', 'b');
is_link($link);// Return FALSE
?>
PHP can not detect symlinks that it creates.
Previous Comments:
------------------------------------------------------------------------
[2013-09-18 20:34:13] giunta dot gaetano at gmail dot com
Ok, then be it
------------------------------------------------------------------------
[2013-09-18 20:21:11] [email protected]
It is not about making sense or not. It is about backward compability and how they
actually behave from a file system point of view.
Think of junction like hard links. You can't see hard link with is_link, no matter
the platform.
------------------------------------------------------------------------
[2013-09-18 20:13:02] giunta dot gaetano at gmail dot com
Mmm, if it walks like a duck and quacks like a duck...
For all scenarios I can figure (backups, deploying code using symlinks), treating a junction as a symlink makes more sense than not doing it.
Right now the only way to tell if a folder is actually a "real one" or not is to use the array_diff trick I put in the test script. It looks hackish, cumbersome, and why should lstat() treat a junction differently than is_link() anyway?)
It is true that windows versions starting with Vista do create symlinks by default, but tools like "Link Shell Extension" or the venerable sysinternals junction.exe still allow one to create Junctions.
------------------------------------------------------------------------
[2013-09-18 19:00:39] [email protected]
Junctions are not symlinks, the result is correct. Also the
junctions pointing to a directory may work. I remember
some windows version specific changes here, where it
ended as symlink or junction (recent always do it as
symlonk afair)
------------------------------------------------------------------------
[2013-09-18 12:51:32] giunta dot gaetano at gmail dot com
Description:
------------
is_link seems to return false for junction points which show up as <JUNCTION> when using the DIR command.
It seems to work for junctions which show up as <SYMLINKD> when using the DIR command.
tested on php 5.3.27 and 5.4.14 (32 bit of course)
Test script:
---------------
<?php
$paths = array(
"linksource",
"linktarget",
"linktarget2"
);
foreach ( $paths as $path )
{
echo "----\n $path\n";
var_dump( is_link( $path ) );
var_dump( is_dir( $path ) );
var_dump( array_diff( stat($path), lstat($path) ) );
}
Expected result:
----------------
results of DIR command:
07/09/2013 15:59 <DIR> linksource
07/09/2013 19:11 <JUNCTION> linktarget [D:\htdocs\linksource]
18/09/2013 14:30 <SYMLINKD> linktarget2 [linksource]
Actual result:
--------------
D:\htdocs>php linktest.php
----
linksource
bool(false)
bool(true)
array(0) {
}
----
linktarget
bool(false)
bool(true)
array(8) {
[2]=>
int(16895)
[8]=>
int(1378562389)
[9]=>
int(1378562389)
[10]=>
int(1378562389)
["mode"]=>
int(16895)
["atime"]=>
int(1378562389)
["mtime"]=>
int(1378562389)
["ctime"]=>
int(1378562389)
}
----
linktarget2
bool(true)
bool(true)
array(8) {
[2]=>
int(16895)
[8]=>
int(1378562389)
[9]=>
int(1378562389)
[10]=>
int(1378562389)
["mode"]=>
int(16895)
["atime"]=>
int(1378562389)
["mtime"]=>
int(1378562389)
["ctime"]=>
int(1378562389)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65697&edit=1