php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61933 realpath not resolving symlinks corrrectly
Submitted: 2012-05-03 21:32 UTC Modified: 2013-02-18 00:35 UTC
Votes:4
Avg. Score:4.0 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: david at panmedia dot co dot nz Assigned:
Status: No Feedback Package: *Directory/Filesystem functions
PHP Version: Irrelevant OS: Windows Vista/7
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-05-03 21:32 UTC] david at panmedia dot co dot nz
Description:
------------
When creating a symlink in Windows to an absolute path with a lower case drive letter, PHP will not resolve the canonicalized absolute pathname (realpath) correctly. 

This is obvious when you have nested symlinks.

When you run realpath of a nested symlink it returns the next symlink it links to, rather than the top absolute pathname.

On Linux it works correctly.

One work around that can be used is:

$link = 'f:\link3';
do {
    $link = realpath($link);
} while (realpath($link) !== false && $link !== realpath($link));

Test script:
---------------
Windows test:
F:\>mkdir target
F:\>mklink /D link1 f:\target
F:\>mklink /D link2 f:\link1
F:\>mklink /D link3 f:\link2
F:\>php -r "var_dump(realpath('link3'));"

Linux test:
$ mkdir target
$ ln -s target link1
$ ln -s link1 link2
$ ln -s link2 link3
$ php -r "var_dump(realpath('link3'));"


Expected result:
----------------
Windows test:
string(9) "F:\target"

Linux test:
string(12) "/root/target"

Actual result:
--------------
Windows test:
string(9) "f:\\link2"

Linux test:
string(12) "/root/target"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-03 22:43 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-05-03 22:43 UTC] pajoye@php.net
It does work, it gives you the target of the given link.

The only difference is an OS specific implementation where all links are resolved.

I suppose you use a TS php on windows and a NTS on linux, right?
 [2012-05-03 22:58 UTC] david at panmedia dot co dot nz
@pajoye I am using VC9 NTS version on Windows.
 [2012-05-03 23:04 UTC] pajoye@php.net
I mean on linux too, is it TS or NTS?
 [2012-05-03 23:11 UTC] david at panmedia dot co dot nz
@pajoye, sorry, NTS on Linux too.
 [2012-05-04 09:28 UTC] pajoye@php.net
SO yes, it is a Linux specific implementation. Nothing that PHP can do about it 
and doing it for php's realpath implementation (windows or other unix, ts mode too 
sometimes) is not possible without issues like performance degradation.
 [2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 14:03:37 2021 UTC