changeset 35512:5cc1becd0493

win32: split a utility function to obtain the volume out of getfstype() This is only done on Windows because it's simple enough to call statfs() on Unix. The goal is to display this in `hg debugfs`.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 29 Dec 2017 22:15:37 -0500
parents d8f408d999f9
children c4caf530b1c7
files mercurial/win32.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/win32.py	Sat Dec 30 21:15:12 2017 -0500
+++ b/mercurial/win32.py	Fri Dec 29 22:15:37 2017 -0500
@@ -428,8 +428,9 @@
         raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER)
     return buf.value
 
-def getfstype(path):
-    """Get the filesystem type name from a directory or file (best-effort)
+def getvolumename(path):
+    """Get the mount point of the filesystem from a directory or file
+    (best-effort)
 
     Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
     """
@@ -442,7 +443,16 @@
     if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size):
         raise ctypes.WinError() # Note: WinError is a function
 
-    t = _kernel32.GetDriveTypeA(buf.value)
+    return buf.value
+
+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.
+    """
+    volume = getvolumename(path)
+
+    t = _kernel32.GetDriveTypeA(volume)
 
     if t == _DRIVE_REMOTE:
         return 'cifs'
@@ -453,7 +463,7 @@
     size = 256
     name = ctypes.create_string_buffer(size)
 
-    if not _kernel32.GetVolumeInformationA(buf.value, None, 0, None, None, None,
+    if not _kernel32.GetVolumeInformationA(volume, None, 0, None, None, None,
                                            ctypes.byref(name), size):
         raise ctypes.WinError() # Note: WinError is a function