#50366 [Fbk-Opn]: realpath() doesn't correctly resolve symlink

2009-12-03 Thread jerico dot dev at gmail dot com
 ID:   50366
 User updated by:  jerico dot dev at gmail dot com
 Reported By:  jerico dot dev at gmail dot com
-Status:   Feedback
+Status:   Open
-Bug Type: Filesystem function related
+Bug Type: Feature/Change Request
 Operating System: Linux
 PHP Version:  5.2.11
 New Comment:

Hi Jani,

thanks a lot for looking into this.

I think the problem is that what is logical depends on what your use
case is. There are two different approaches to resolving paths to
canonical (physical) locations with symlinks:
1) Resolving .. first, then symlinks. This is AFAIK the default for the
*nix command line (try cd'ing or ls'ing the example location and you'll
see what I mean).
2) Resolving symlinks first, then .. There is one tool on Linux (that I
know of) that behaves like this: readlink -e

I agree with you that there ARE use cases where you want 2). I've
changed the bug category to feature request to reflect this. Sorry for
filing a bug in the first place. :-(

There are many use cases, though, where realpath()/chdir() behavior is
NOT useful (otherwise the OS would probably have chosen realpath/chdir
logic as it's default ;-) ). The problem is that AFAIK PHP currently has
no way of doing 1). Try

chdir('/home/user/test/app/lib/symlink/tests/../../..');
echo getcwd().\n;

To see what I mean.

Also see 
http://bugs.php.net/bug.php?id=37603 and
http://bugs.php.net/bug.php?id=46260
which request very similar features.

The only way I know to achieve 1) would be going to OS-level (e.g.
using `cd ...` or s.th. like that) which is awkward and not portable.

If you know a portable way to map a relative or absolute path with
symlinks to it's physical location OS style in PHP then it would be
extremely useful for me (and probably others) if you could share your
knowledge. It's entirely possible that I miss something.

If you feel extremely helpful ;-) then you also might extend the PHP
documentation of realpath()/chdir() and make it clear that both treat
symlinks the same way as readlink -e does. There already is a user
comment for chdir() saying that but I think it'd be worth mentioning at
a more prominent location.


Previous Comments:


[2009-12-03 08:13:46] j...@php.net

realpath() expands all symbolic links and resolves references to
'/./', '/../' and extra '/' characters in the input path . and return
the canonicalized absolute pathname. 

And since it first resolves to /home/user/test/something/tests from
where you go down 3 levels, of course you get /home/user/ ?

See this:

# php -r  'echo realpath(/home/jani/test/app/lib/symlink/tests/),
\n;'
/home/jani/test/something/tests

# php -r  'echo
realpath(/home/jani/test/app/lib/symlink/tests/../../..), \n;'
/home/jani





[2009-12-03 05:42:33] jerico dot dev at gmail dot com

Reproduced with php5.2-200912022330 compiled on Ubuntu Jaunty



[2009-12-02 22:40:51] j...@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/





[2009-12-02 22:07:41] jerico dot dev at gmail dot com

Description:

realpath() doesn't resolve symlinks correctly when followed by /..

Reproduce code:
---
echo realpath('/home/user/test/app/lib/symlink/tests/../../..');

where symlink points to /home/user/test/something

Expected result:

/home/user/test/app

Actual result:
--
/home/user





-- 
Edit this bug report at http://bugs.php.net/?id=50366edit=1



#50366 [Fbk-Opn]: realpath() doesn't correctly resolve symlink

2009-12-02 Thread jerico dot dev at gmail dot com
 ID:   50366
 User updated by:  jerico dot dev at gmail dot com
 Reported By:  jerico dot dev at gmail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: Filesystem function related
 Operating System: Linux
 PHP Version:  5.2.11
 New Comment:

Reproduced with php5.2-200912022330 compiled on Ubuntu Jaunty


Previous Comments:


[2009-12-02 22:40:51] j...@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/





[2009-12-02 22:07:41] jerico dot dev at gmail dot com

Description:

realpath() doesn't resolve symlinks correctly when followed by /..

Reproduce code:
---
echo realpath('/home/user/test/app/lib/symlink/tests/../../..');

where symlink points to /home/user/test/something

Expected result:

/home/user/test/app

Actual result:
--
/home/user





-- 
Edit this bug report at http://bugs.php.net/?id=50366edit=1