[PATCH 3 of 5] osutil: add a function to show the mount point of the filesystem
Matt Harbison
mharbison72 at gmail.com
Sat Dec 30 01:37:32 EST 2017
# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1514606054 18000
# Fri Dec 29 22:54:14 2017 -0500
# Node ID 6cfb98df0f014d6ca3b1d80f26ae0744a2c1c1c8
# Parent 32d2484a8565412b23dcb3eda14f5470c9632d13
osutil: add a function to show the mount point of the filesystem
For now, this is Windows only, since Linux doesn't have the value in its statfs
structure, and I don't have a BSD system to test with. I assume since the
version was just incremented yesterday, it doesn't have to be incremented again.
diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c
--- a/mercurial/cext/osutil.c
+++ b/mercurial/cext/osutil.c
@@ -1316,6 +1316,20 @@
return NULL;
}
+static PyObject *getfsmountpoint(PyObject *self, PyObject *args)
+/* given a directory path, return filesystem mount point (best-effort) */
+{
+ PyObject *val = NULL;
+ char *volume = getvolumepath(args);
+
+ if (!volume)
+ return NULL;
+
+ val = Py_BuildValue("s", volume);
+ free(volume);
+ return val;
+}
+
static PyObject *getfstype(PyObject *self, PyObject *args)
/* given a directory path, return filesystem type name (best-effort) */
{
@@ -1402,6 +1416,11 @@
{"getfstype", (PyCFunction)getfstype, METH_VARARGS,
"get filesystem type (best-effort)\n"},
#endif
+#if defined(_WIN32)
+ {"getfsmountpoint", (PyCFunction)getfsmountpoint, METH_VARARGS,
+ "get filesystem mount point (best-effort)\n"},
+#endif
+
#ifdef __APPLE__
{
"isgui", (PyCFunction)isgui, METH_NOARGS,
diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -157,6 +157,7 @@
from .. import win32
getfstype = win32.getfstype
+ getfsmountpoint = win32.getvolumename
_kernel32 = ctypes.windll.kernel32
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1520,6 +1520,13 @@
return ''.join(result)
+def getfsmountpoint(dirpath):
+ '''Get the filesystem mount point from a directory (best-effort)
+
+ Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
+ '''
+ return getattr(osutil, 'getfsmountpoint', lambda x: None)(dirpath)
+
def getfstype(dirpath):
'''Get the filesystem type name from a directory (best-effort)
More information about the Mercurial-devel
mailing list