diff --git a/ntfsutils/fs.py b/ntfsutils/fs.py index c90a711..7f6629c 100644 --- a/ntfsutils/fs.py +++ b/ntfsutils/fs.py @@ -28,7 +28,7 @@ MAX_PATH = 260 -INVALID_HANDLE_VALUE = -1 +INVALID_HANDLE_VALUE = HANDLE(-1).value class FILETIME(ctypes.Structure): _fields_ = [("dwLowDateTime", DWORD), diff --git a/ntfsutils/junction.py b/ntfsutils/junction.py index 4c49802..b0da63c 100644 --- a/ntfsutils/junction.py +++ b/ntfsutils/junction.py @@ -100,10 +100,13 @@ def unparsed_unconvert(path): return path def isjunction(path): - if not os.path.exists(path) or not fs.junctions_supported(path): + if not fs.junctions_supported(path): return False attrs = GetFileAttributes(path) + if attrs == DWORD(-1).value: + return False + return bool((attrs & fs.FILE_ATTRIBUTE_DIRECTORY) and (attrs & fs.FILE_ATTRIBUTE_REPARSE_POINT)) @@ -157,7 +160,7 @@ def readlink(path): 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, + hlink = CreateFile(path, 0, fs.FILE_SHARE_READ, None, fs.OPEN_EXISTING, fs.FILE_FLAG_OPEN_REPARSE_POINT | fs.FILE_FLAG_BACKUP_SEMANTICS, None)