Bug #72738 [Ver]: realpath() expands junction points

From: Date: Mon, 16 Nov 2020 13:22:49 +0000
Subject: Bug #72738 [Ver]: realpath() expands junction points
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230381@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72738&edit=1

 ID:                 72738
 Updated by:         cmb@php.net
 Reported by:        anrdaemon at freemail dot ru
 Summary:            realpath() expands junction points
 Status:             Verified
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Windows
 PHP Version:        7.1.0beta1
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

I had a closer look, but I'm not really sure how it is
supposed to work.  In bug #72642 pajoye said:

> This function solves symbolic link only, not junction, mount
> point or hard link.

However, that is not correct; actually, exactly one level of links
is resolved on Windows.

pajoye continues:

> and it is on purpose and by design. The same applies to other
> platforms with hard links for example.

I don't know how other platforms deal with this.  Apparently,
POSIX is not clear about this[1], but the ln man page[2] mentions
that hardlinked directories are usually not supported at all.

Anyhow, symlinked directories are not recursively resolved on
Windows (only one level like for hardlinked directories), and that
would be a bug.

[1] <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html>
[2] <https://man7.org/linux/man-pages/man1/ln.1.html>


Previous Comments:
------------------------------------------------------------------------
[2016-08-02 22:29:59] cmb@php.net

I can confirm this behavior. Obviously, the invariant

  realpath(realpath($x)) == realpath($x)

does not hold in this case.

------------------------------------------------------------------------
[2016-08-02 19:31:28] anrdaemon at freemail dot ru

Description:
------------
On Windows, realpath() expands the directory junction points.
According to an apparently authoritative assesment of pajoye@php.net in the https://bugs.php.net/bug.php?id=72642 , this
shouldn't happen.

Test script:
---------------
<?php

$rootdir = substr(getenv('SystemRoot'), 0, 3);
$tmpdir = getenv('TEMP');
shell_exec("mklink /J \"{$rootdir}home\" \"{$rootdir}Users\"");
shell_exec("mklink /J \"{$tmpdir}\\test.dir\"
\"{$rootdir}home\\Public\\Desktop\"");
$file = "{$tmpdir}\\test.dir\\desktop.ini";
$rfile1 = realpath($file);
$rfile2 = realpath($rfile1);
printf("orig.file name: %s\n", $file);
printf("realpath(name): %s (%s)\n", $rfile1, $file == $rfile1 ? 'Ok' :
'fail');
printf("THE real name:  %s (%s)\n", $rfile2, $file == $rfile2 ? 'Ok' :
'fail');

rmdir("{$rootdir}home");
rmdir("{$tmpdir}\\test.dir");


Expected result:
----------------
According to pajoye@php.net, expansion shouldn't happen, and all paths must be the same == the
original path.

Actual result:
--------------
All paths are different. On each iteration, realpath() only expands a portion of nested junctions.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72738&edit=1


Thread (3 messages)

« previous php.bugs (#230381) next »