[issue15748] Various symlink test failures in test_shutil on FreeBSD

Trent Nelson report at bugs.python.org
Wed Aug 22 00:28:57 CEST 2012


Trent Nelson added the comment:

Well, bugger me, check this out:


import os
import stat
import tempfile

d = tempfile.mkdtemp()
src = os.path.join(d, 'foo')
dst = os.path.join(d, 'bar')
src_link = os.path.join(d, 'baz')
dst_link = os.path.join(d, 'qux')

sf = open(dst, 'w')
sf.write('foo')
sf.flush()
sf.close()

df = open(dst, 'w')
df.write('bar')
df.flush()
df.close()

os.symlink(src, src_link)
os.symlink(dst, dst_link)

os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)

os.readlink(dst_link)
os.readlink(src_link)


Results of the last two calls:
>>> os.readlink(dst_link)

path 1: /tmp/tmpfz5v6h/qux, length 1: 18, buf 1: /tmp/tmpfz5v6h/bar
path 2: /tmp/tmpfz5v6h/qux, length 2: 18, buf 2: /tmp/tmpfz5v6h/bar
'/tmp/tmpfz5v6h/bar'
[73299 refs]
>>> os.readlink(src_link)

path 1: /tmp/tmpfz5v6h/baz, length 1: 24, buf 1: /tmp/tmpfz5v6h/foo
path 2: /tmp/tmpfz5v6h/baz, length 2: 24, buf 2: /tmp/tmpfz5v6h/foo
'/tmp/tmpfz5v6h/foo\x00\x00\x00\x00\x00\x00'
[73299 refs]

So, without the os.lchmod() call, the length is returned correctly.  With it, it gets returned as 24.  Looks like an OS bug.

----------

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


More information about the Python-bugs-list mailing list