def readlink(path):
# Make sure the path exists and is actually a junction
if not isjunction(path):
raise Exception("%s does not exist or is not a junction" % path)
hlink = CreateFile(path, fs.GENERIC_READ, fs.FILE_SHARE_READ, None,
fs.OPEN_EXISTING,
fs.FILE_FLAG_OPEN_REPARSE_POINT | fs.FILE_FLAG_BACKUP_SEMANTICS,
None)
if hlink == fs.INVALID_HANDLE_VALUE:
raise WinError()
try:
(junctioninfo, infolen) = new_junction_reparse_buffer()
dummy = DWORD(0)
res = DeviceIoControl(
hlink,
FSCTL_GET_REPARSE_POINT,
None,
0,
byref(junctioninfo),
infolen,
byref(dummy),
None)
if res == 0:
raise WinError()
return unparsed_unconvert(junctioninfo.SubstituteNameBuffer)
finally:
CloseHandle(hlink)
评论列表
文章目录