Skip to content

Commit e4e0da4

Browse files
author
martin.v.loewis
committed
Issue #3881: Help Tcl to load even when started through the
unreadable local symlink to "Program Files" on Vista. git-svn-id: http://svn.python.org/projects/python/trunk@68893 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 6c38d99 commit e4e0da4

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lib/lib-tk/FixTk.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,48 @@
1010
# <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to
1111
# the real Tcl library will do.
1212

13+
# Expand symbolic links on Vista
14+
try:
15+
import ctypes
16+
ctypes.windll.kernel32.GetFinalPathNameByHandleW
17+
except (ImportError, AttributeError):
18+
def convert_path(s):
19+
return s
20+
else:
21+
def convert_path(s):
22+
if isinstance(s, str):
23+
s = s.decode("mbcs")
24+
hdir = ctypes.windll.kernel32.\
25+
CreateFileW(s, 0x80, # FILE_READ_ATTRIBUTES
26+
1, # FILE_SHARE_READ
27+
None, 3, # OPEN_EXISTING
28+
0x02000000, # FILE_FLAG_BACKUP_SEMANTICS
29+
None)
30+
if hdir == -1:
31+
# Cannot open directory, give up
32+
return s
33+
buf = ctypes.create_unicode_buffer(u"", 32768)
34+
res = ctypes.windll.kernel32.\
35+
GetFinalPathNameByHandleW(hdir, buf, len(buf),
36+
0) # VOLUME_NAME_DOS
37+
ctypes.windll.kernel32.CloseHandle(hdir)
38+
if res == 0:
39+
# Conversion failed (e.g. network location)
40+
return s
41+
s = buf[:res]
42+
# Ignore leading \\?\
43+
if s.startswith(u"\\\\?\\"):
44+
s = s[4:]
45+
return s
46+
1347
prefix = os.path.join(sys.prefix,"tcl")
1448
if not os.path.exists(prefix):
1549
# devdir/../tcltk/lib
1650
prefix = os.path.join(sys.prefix, os.path.pardir, "tcltk", "lib")
1751
prefix = os.path.abspath(prefix)
1852
# if this does not exist, no further search is needed
1953
if os.path.exists(prefix):
54+
prefix = convert_path(prefix)
2055
if not os.environ.has_key("TCL_LIBRARY"):
2156
for name in os.listdir(prefix):
2257
if name.startswith("tcl"):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ Core and Builtins
145145
Library
146146
-------
147147

148+
- Issue #3881: Help Tcl to load even when started through the
149+
unreadable local symlink to "Program Files" on Vista.
150+
148151
- Issue #4710: Extract directories properly in the zipfile module;
149152
allow adding directories to a zipfile.
150153

0 commit comments

Comments
 (0)