[New-bugs-announce] [issue6975] symlinks incorrectly resolved on Linux

Sylwester Warecki report at bugs.python.org
Wed Sep 23 07:55:13 CEST 2009


New submission from Sylwester Warecki <swarecki at cox.net>:

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()

----------
components: Library (Lib)
messages: 93027
nosy: swarecki
severity: normal
status: open
title: symlinks incorrectly resolved on Linux
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6975>
_______________________________________


More information about the New-bugs-announce mailing list