Bug #77639 [Csd->ReO]: realpath resolves NTFS junctions which are not symlinks

From: Date: Tue, 19 Feb 2019 21:40:13 +0000
Subject: Bug #77639 [Csd->ReO]: realpath resolves NTFS junctions which are not symlinks
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219649@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77639&edit=1

 ID:                 77639
 Updated by:         requinix@php.net
 Reported by:        mesaverde228 at gmail dot com
-Summary:            Wrong behavior of getting paths for symlink
+Summary:            realpath resolves NTFS junctions which are not
                     symlinks
-Status:             Closed
+Status:             Re-Opened
 Type:               Bug
 Package:            *Directory/Filesystem functions
 Operating System:   Windows/Linux
 PHP Version:        7.1.26
 Block user comment: N
 Private report:     N

 New Comment:

There is still a bug here, even if it wasn't the one you were expecting.

> there is no cross-platform solution to create sym-link that can be later
> recognized by PHP the same on different OS :(
The problems come from Windows and NTFS restrictions. Specifically, Windows requires the
SeCreateSymbolicLinkPrivilege privilege, which Administrator has but it can also be granted to other
accounts. Windows also does not support symlinked directories. But it can do symlinked files and
hardlinked/junctioned directories.

Besides that, PHP is as cross-platform as it can be.


Previous Comments:
------------------------------------------------------------------------
[2019-02-19 21:29:13] mesaverde228 at gmail dot com

I assume issue can be closed because for subfolders within "linked" directory exists
another separate ticket

------------------------------------------------------------------------
[2019-02-19 21:21:15] mesaverde228 at gmail dot com

yes, you are right.

"ln" tool is not a solution for me :(

and as I can see there is no cross-platform solution to create sym-link that can be later recognized
by PHP the same on different OS :(

------------------------------------------------------------------------
[2019-02-19 21:06:30] requinix@php.net

ln is not creating a symlink. Rather, it appears to be creating a copy.

1. If it were a symlink then dir would have shown it as such.
2. By default Windows requires admin privileges to create symlinks.
3. Create a file in one directory and it will not appear in the other.
4. If I create a large file in the original and try to ln -s to it, ln takes time when the operation
should be instant.

------------------------------------------------------------------------
[2019-02-19 20:23:25] mesaverde228 at gmail dot com

Ok, install git and use "ln" from distribution to create symbolik link like on Linux
system

rm -rf D:\test\symlinkedcachefolder
ln -s D:\test\realcachefolder D:\test\symlinkedcachefolder
dir

output

D:\test>dir
 Volume in drive D is dev
 Volume Serial Number is ECD3-824B

 Directory of D:\test

02/19/2019  11:14 PM    <DIR>          .
02/19/2019  11:14 PM    <DIR>          ..
02/19/2019  09:51 PM    <DIR>          realcachefolder
02/19/2019  11:14 PM    <DIR>          symlinkedcachefolder
               0 File(s)              0 bytes
               4 Dir(s)  34,891,960,320 bytes free


Next use steps from previous STR

php -r "var_dump(realpath('D:/test/symlinkedcachefolder'));"
php -r "var_dump(__DIR__);"

Will output

D:\test\symlinkedcachefolder>php -r
"var_dump(realpath('D:/test/symlinkedcachefolder'));"
string(28) "D:\test\symlinkedcachefolder"

D:\test\symlinkedcachefolder>php -r "var_dump(__DIR__);"
string(28) "D:\test\symlinkedcachefolder"

and script will return following

D:\test\symlinkedcachefolder>php index.php
array(4) {
  ["realpath(__DIR__)"]=>
  string(28) "D:\test\symlinkedcachefolder"
  ["realpath("D:\test\symlinkedcachefolder\gretta")"]=>
  bool(false)
  ["dirname(__DIR__)"]=>
  string(7) "D:\test"
  ["dirname(__DIR__ . "\gretta")"]=>
  string(28) "D:\test\symlinkedcachefolder"
}

Totally different result comparing to junctions or native soft links in windows and not the same as
on Linux fo links created using "ln" tool

------------------------------------------------------------------------
[2019-02-19 19:46:51] requinix@php.net

You cannot compare a Linux symlink with an NTFS junction. They are two different filesystem
features.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=77639


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


Thread (17 messages)

« previous php.bugs (#219649) next »