[PATCH 1 of 5] pure: implement osutil.getfstype() on Windows

Yuya Nishihara yuya at tcha.org
Sat Dec 30 20:49:18 EST 2017


On Sat, 30 Dec 2017 01:37:30 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1514600899 18000
> #      Fri Dec 29 21:28:19 2017 -0500
> # Node ID 47921e6734f8f9e1536a8bd9e4b33e77baca7337
> # Parent  a210a1a19734a60d52e2b718dfcfccdd5356c03b
> pure: implement osutil.getfstype() on Windows

Looks good.

> +def getfstype(path):
> +    """Get the filesystem type name from a directory or file (best-effort)
> +
> +    Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
> +    """
> +    # realpath() calls GetFullPathName()
> +    realpath = os.path.realpath(path)
> +
> +    size = len(realpath) + 1
> +    buf = ctypes.create_string_buffer(size)
> +
> +    if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size):
> +        raise ctypes.WinError() # Note: WinError is a function
> +
> +    t = _kernel32.GetDriveTypeA(buf.value)
> +
> +    if t == 4:  # DRIVE_REMOTE
> +        return 'cifs'
> +    elif t not in (2, 3, 5, 6):
> +        # DRIVE_UNKNOWN, DRIVE_NO_ROOT_DIR, unknown

Perhaps named constants are preferred.

_DRIVE_REMOTE = 4
...


More information about the Mercurial-devel mailing list