classification
Title: symlinks incorrectly resolved on Linux
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 2.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, ezio.melotti, markon, swarecki (4)
Priority: normal Keywords patch

Created on 2009-09-23 05:55 by swarecki, last changed 2009-10-18 09:07 by markon.

Files
File name Uploaded Description Edit Remove
issue6975.patch markon, 2009-10-16 21:05 Patch provided for issue 6975
Messages (6)
msg93027 - (view) Author: Sylwester Warecki (swarecki) Date: 2009-09-23 05:55
Hi

The behavior of os.realpath function on Linux is different from the one 
presented by the system. 
Although the path (pointing to the linked dir) is correct
and is recognized by os.path.exists once it is resolved
by the realpath() it does not exist - at the end of the 
resolved path you will see the additional parent directory name.
you will see
..... /two/two at the end of the path.

Below is the code that shows the issue.

def linkGen():
  import os
  print os.getcwd()
  test = "./test"
  os.system( "rm -rf " + test  )  
  #os.mkdir( test )
  os.makedirs( test + "/one" )
  os.makedirs( test + "/two" )
  os.symlink( "../two", test + "/two/this_dir" )
  os.symlink( "../two/this_dir/this_dir/this_dir/this_dir/", test + 
"/one/that_dir" )
  print test + "/one/that_dir", "EXISTS?",   
  print os.path.exists( test + "/one/that_dir" )
  print os.path.realpath( test + "/one/that_dir" ), "EXISTS?", 
  print os.path.exists( os.path.realpath( test + "/one/that_dir" ) )
  os.system( "ls -l " + test + "/one/that_dir" )
  # the line above will show that system can see the directory just fine

linkGen()
msg93029 - (view) Author: Sylwester Warecki (swarecki) Date: 2009-09-23 05:56
Hi
I meant of course 
os.path.realpath()
Sylwester
msg94149 - (view) Author: Marco Buccini (markon) Date: 2009-10-16 21:05
I've provided a patch.

I've also added a new test, and it passes.
msg94179 - (view) Author: Marco Buccini (markon) Date: 2009-10-17 15:15
I've just found a similar bug:
http://bugs.python.org/issue1646838

However, does os.path.realpath's behavior have to be as the one
specified by the POSIX standard (
http://www.kernel.org/doc/man-pages/online/pages/man3/realpath.3.html )?
If we wanted to follow the standard, we should break the
retro-compatibility, since we should raise an exception in the case the
path passed as argument doesn't exist.
msg94199 - (view) Author: Sylwester Warecki (swarecki) Date: 2009-10-18 03:00
Marco,

Thanks for looking deeper into it.
I would like to check the solution ASAP.
We have really crazy dir structure which can catch a lot of
the unexpected problems with paths, links, circular links etc.

Should I expect the new version to generate the exception
as you suggested?

Best Regards,
    Sywlester Warecki

Marco Buccini wrote:
> Marco Buccini <marcusbu@gmail.com> added the comment:
>
> I've just found a similar bug:
> http://bugs.python.org/issue1646838
>
> However, does os.path.realpath's behavior have to be as the one
> specified by the POSIX standard (
> http://www.kernel.org/doc/man-pages/online/pages/man3/realpath.3.html )?
> If we wanted to follow the standard, we should break the
> retro-compatibility, since we should raise an exception in the case the
> path passed as argument doesn't exist.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue6975>
> _______________________________________
>
>
msg94209 - (view) Author: Marco Buccini (markon) Date: 2009-10-18 09:07
>Thanks for looking deeper into it.
>I would like to check the solution ASAP.
>We have really crazy dir structure which can catch a lot of
>the unexpected problems with paths, links, circular links etc.

Oh well, so you can see if the patch works correctly on all paths :)
 
>Should I expect the new version to generate the exception
>as you suggested?

 
Unfortunately I'm not God, so I cannot change the "code" of the current
implementation of os.path.realpath (raising an OSError exception)
without breaking any existing code. 
So, consider using the current implementation of os.path.realpath ;)
If you experience other strange behaviors, then open a new bug report.

Bye!
History
Date User Action Args
2009-10-18 09:07:21markonsetmessages: + msg94209
2009-10-18 03:00:11swareckisetmessages: + msg94199
2009-10-17 15:15:23markonsetmessages: + msg94179
2009-10-17 14:48:48markonsetnosy: + brett.cannon
2009-10-17 01:09:48ezio.melottisetpriority: normal
nosy: + ezio.melotti

stage: patch review
2009-10-16 21:05:55markonsetfiles: + issue6975.patch

nosy: + markon
messages: + msg94149

keywords: + patch
2009-09-23 05:56:20swareckisetmessages: + msg93029
2009-09-23 05:55:12swareckicreate