Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.path.realpath() get the wrong result #48904

Closed
dirlt mannequin opened this issue Dec 13, 2008 · 7 comments
Closed

os.path.realpath() get the wrong result #48904

dirlt mannequin opened this issue Dec 13, 2008 · 7 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dirlt
Copy link
Mannequin

dirlt mannequin commented Dec 13, 2008

BPO 4654
Nosy @loewis, @ezio-melotti, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2010-06-19.23:36:03.292>
created_at = <Date 2008-12-13.08:47:38.768>
labels = ['type-bug', 'library']
title = 'os.path.realpath() get the wrong result'
updated_at = <Date 2010-06-19.23:36:03.291>
user = 'https://bugs.python.org/dirlt'

bugs.python.org fields:

activity = <Date 2010-06-19.23:36:03.291>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2010-06-19.23:36:03.292>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2008-12-13.08:47:38.768>
creator = 'dirlt'
dependencies = []
files = []
hgrepos = []
issue_num = 4654
keywords = []
message_count = 7.0
messages = ['77719', '108202', '108205', '108215', '108217', '108218', '108219']
nosy_count = 6.0
nosy_names = ['loewis', 'ezio.melotti', 'r.david.murray', 'dirlt', 'l0nwlf', 'BreamoreBoy']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4654'
versions = ['Python 2.3']

@dirlt
Copy link
Mannequin Author

dirlt mannequin commented Dec 13, 2008

I found the problem when i install a small tool which I wrote on the
each machine in the company.the problem is simplified as follows:
there are three files
1./home/share/temp/a a regular file
2./home/share/a.lnk which is symbolic link to the /home/share/temp/a
3./home/share/temp/test.py whose contents are
#!/usr/bin/env python

import os
import sys
print sys.version
print os.uname()
print os.path.realpath("/home/share/temp/../a.lnk")
print os.path.abspath("/home/share/temp/../a.lnk")

and I ran the python script on two different machines,but the version
of python interpreters are the same,and both of them are 64 bits machine,
but the result of os.path.realpath is different,one is
--------------------------------------------------------
2.3.4 (#1, Feb 2 2005, 11:44:13)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)]
('Linux', 'tc-com-test00.tc.baidu.com', '2.6.9-52bs', '#2 SMP Fri Jan 26
13:34:38 CST 2007', 'x86_64')
/home/share/a.lnk
/home/share/a.lnk

another is
-----------------------------------------------------------
2.3.4 (#1, Dec 11 2007, 05:28:55)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)]
('Linux', 'tc-ecom-dev00.tc.baidu.com', '2.6.9-52bs', '#2 SMP Fri Jan 26
13:34:38 CST 2007', 'x86_64')
/home/share/temp/temp/a
/home/share/a.lnk

But obviously the first one os.path.realpath(...) should be
/home/share/temp/a instead of /home/share/a.lnk
and the second on os.path.realpath(...) should also be
/home/share/temp/a instaed of /home/share/temp/temp/a

@dirlt dirlt mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 13, 2008
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jun 19, 2010

An issue with Python 2.3, can this be closed or is it still a problem with Python 2.7 or any of the Python 3 versions?

@l0nwlf
Copy link
Mannequin

l0nwlf mannequin commented Jun 19, 2010

No such issue on python 2.6, 2.7, 3.2.

>>> print(os.path.realpath('/Users/l0nwlf/Desktop/tmp/../decotest.lnk'))
/Users/l0nwlf/Desktop/decotest.lnk
I think this issue can be closed.
However, I came with a different issue while testing on 2.6, trunk and 3.2.

>>> print(os.path.realpath('~/Desktop/tmp/../decotest.lnk'))
/Volumes/CoreHD/py3k/~/Desktop/decotest.lnk

@bitdancer
Copy link
Member

Your different issue looks like a correct result to me. ~ is not automatically expanded.

@l0nwlf
Copy link
Mannequin

l0nwlf mannequin commented Jun 19, 2010

By different issue I meant expected but non-useful output.
Although it does exactly what it is supposed to do, but expanding tilde (~) to $HOME could have been the default behavior(more user-friendly I should say). Don't know if that is worth it but the scale seems more on the negative side.

@bitdancer
Copy link
Member

I can confirm this works correctly on 32 bit Linux under 2.6.4. Since it is unlikely the width matters to this issue I'm going to close it. If anyone has a case where it fails we can reopen.

@bitdancer
Copy link
Member

Somebody long ago made the decision that ~ is only expanded if you call expanduser. I don't think this decision is likely to get changed.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant