def _readlink_deep(path, seen=None): if seen is None: seen = set() # These error codes indicate that we should stop reading links and # return the path we currently have. # 1: ERROR_INVALID_FUNCTION # 2: ERROR_FILE_NOT_FOUND # 3: ERROR_DIRECTORY_NOT_FOUND # 5: ERROR_ACCESS_DENIED # 21: ERROR_NOT_READY (implies drive with no media) # 32: ERROR_SHARING_VIOLATION (probably an NTFS paging file) # 50: ERROR_NOT_SUPPORTED (implies no support for reparse points) # 67: ERROR_BAD_NET_NAME (implies remote server unavailable) # 87: ERROR_INVALID_PARAMETER # 4390: ERROR_NOT_A_REPARSE_POINT # 4392: ERROR_INVALID_REPARSE_DATA # 4393: ERROR_REPARSE_TAG_INVALID allowed_winerror = 1, 2, 3, 5, 21, 32, 50, 67, 87, 4390, 4392, 4393 while normcase(path) not in seen: seen.add(normcase(path)) try: path = _nt_readlink(path) except OSError as ex: if ex.winerror in allowed_winerror: break raise except ValueError: # Stop on reparse points that are not symlinks break return path
def _readlink_deep(path, seen=None): if seen is None: seen = set() while normcase(path) not in seen: seen.add(normcase(path)) try: path = _nt_readlink(path) except OSError as ex: # Stop on file (2) or directory (3) not found, or # paths that are not reparse points (4390) if ex.winerror in (2, 3, 4390): break raise except ValueError: # Stop on reparse points that are not symlinks break return path
def _readlink_deep(path): # These error codes indicate that we should stop reading links and # return the path we currently have. # 1: ERROR_INVALID_FUNCTION # 2: ERROR_FILE_NOT_FOUND # 3: ERROR_DIRECTORY_NOT_FOUND # 5: ERROR_ACCESS_DENIED # 21: ERROR_NOT_READY (implies drive with no media) # 32: ERROR_SHARING_VIOLATION (probably an NTFS paging file) # 50: ERROR_NOT_SUPPORTED (implies no support for reparse points) # 67: ERROR_BAD_NET_NAME (implies remote server unavailable) # 87: ERROR_INVALID_PARAMETER # 4390: ERROR_NOT_A_REPARSE_POINT # 4392: ERROR_INVALID_REPARSE_DATA # 4393: ERROR_REPARSE_TAG_INVALID allowed_winerror = 1, 2, 3, 5, 21, 32, 50, 67, 87, 4390, 4392, 4393 seen = set() while normcase(path) not in seen: seen.add(normcase(path)) try: old_path = path path = _nt_readlink(path) # Links may be relative, so resolve them against their # own location if not isabs(path): # If it's something other than a symlink, we don't know # what it's actually going to be resolved against, so # just return the old path. if not islink(old_path): path = old_path break path = normpath(join(dirname(old_path), path)) except OSError as ex: if ex.winerror in allowed_winerror: break raise except ValueError: # Stop on reparse points that are not symlinks break return path