Doc #72738 [Ver->Csd]: realpath() expands junction points

From: Date: Thu, 19 Nov 2020 13:30:11 +0000
Subject: Doc #72738 [Ver->Csd]: realpath() expands junction points
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18130@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: phpdocbot@php.net Reported by: anrdaemon at freemail dot ru Summary: realpath() expands junction points -Status: Verified +Status: Closed Type: Documentation Problem Package: Filesystem function related Operating System: Windows PHP Version: 7.1.0beta1 Assigned To: cmb Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmb Revision: http://git.php.net/?p=doc/en.git;a=commit;h=cfa78d6bb99348a6f898b133136bcfc256804b09 Log: Fix #72738: realpath() expands junction points Previous Comments: ------------------------------------------------------------------------ [2020-11-18 17:15:16] cmb@php.net I talked with other members of the PHPonWindows team, and our stance is to leave that as is. The behavior should be documented, of course. ------------------------------------------------------------------------ [2020-11-16 13:22:49] cmb@php.net 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> ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#18130) next »