Bug #69473 [NEW]: bug in symlink() prevents relative symlinks on Windows
| From: | email at spikx dot net | Date: | Thu, 16 Apr 2015 20:29:47 +0000 |
| Subject: | Bug #69473 [NEW]: bug in symlink() prevents relative symlinks on Windows | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-192140@lists.php.net to get a copy of this message | ||
From: email at spikx dot net
Operating system: Windows 7
PHP version: 5.6.8
Package: Win32API related
Bug Type: Bug
Bug description:bug in symlink() prevents relative symlinks on Windows
Description:
------------
As far as I checked, the following applies to any PHP version since the
symlink function was introduced (in PHP 5.3).
Currently it is impossible under Windows to create relative symbolic
links with PHP's symlink function. It will always fail with the message
"Could not fetch file information". The reason is the following:
At line #169 (
https://github.com/php/php-src/blob/master/ext/standard/link_win32.c#L169
) the function checks, if the $target ("topath" in the C function)
actually exists:
if ((attr = GetFileAttributes(topath)) == INVALID_FILE_ATTRIBUTES) { ...
}
However, the Win32API function "GetFileAttributes" expects the path to
be either absolute or relative **to the CWD**! This means that this
check will always fail, if you want to use a relative symlink, since the
relative path of the symlink is relative to the $source's directory, not
relative to the CWD.
Test script:
---------------
<?php
mkdir('foo1');
mkdir('foo2');
symlink( '../foo2', 'foo1/foo3' );
Expected result:
----------------
/foo1 should contain a directory symlink to ../foo2 (i.e. the /foo2
directory in the root folder)
Actual result:
--------------
Under Windows:
Warning: symlink(): Could not fetch file information(error 2) in
index.php on line 6
Under Linux:
foo1 contains a directory symlink to ../foo2 (i.e. the foo2 directory in
CWD)
--
Edit bug report at https://bugs.php.net/bug.php?id=69473&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69473&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69473&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69473&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69473&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69473&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69473&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69473&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69473&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69473&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69473&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69473&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69473&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69473&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69473&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69473&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69473&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69473&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69473&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69473&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69473&r=mysqlcfg