Patchwork [5,of,5] osutil: implement getfsmountpoint() on BSD systems

login
register
mail settings
Submitter Matt Harbison
Date Dec. 30, 2017, 6:37 a.m.
Message ID <91eb2a6192382543f57d.1514615854@Envy>
Download mbox | patch
Permalink /patch/26505/
State Accepted, archived
Headers show

Comments

Matt Harbison - Dec. 30, 2017, 6:37 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1514609752 18000
#      Fri Dec 29 23:55:52 2017 -0500
# Node ID 91eb2a6192382543f57d93404b0252e30a1a41ab
# Parent  b02665ecb0c1653ace0ac1ed7812ffd42317fb43
osutil: implement getfsmountpoint() on BSD systems

I don't have a BSD system handy to test this, but it looks simple enough from
the man page.

Patch

diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c
--- a/mercurial/cext/osutil.c
+++ b/mercurial/cext/osutil.c
@@ -1112,6 +1112,24 @@ 
 }
 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
 
+#if defined(HAVE_BSD_STATFS)
+static PyObject *getfsmountpoint(PyObject *self, PyObject *args)
+/* given a directory path, return filesystem mount point (best-effort) */
+{
+	const char *path = NULL;
+	struct statfs buf;
+	int r;
+	if (!PyArg_ParseTuple(args, "s", &path))
+		return NULL;
+
+	memset(&buf, 0, sizeof(buf));
+	r = statfs(path, &buf);
+	if (r != 0)
+		return PyErr_SetFromErrno(PyExc_OSError);
+	return Py_BuildValue("s", buf.f_mntonname);
+}
+#endif /* defined(HAVE_BSD_STATFS) */
+
 static PyObject *unblocksignal(PyObject *self, PyObject *args)
 {
 	int sig = 0;
@@ -1416,7 +1434,7 @@ 
 	{"getfstype", (PyCFunction)getfstype, METH_VARARGS,
 	 "get filesystem type (best-effort)\n"},
 #endif
-#if defined(_WIN32)
+#if defined(HAVE_BSD_STATFS) || defined(_WIN32)
 	{"getfsmountpoint", (PyCFunction)getfsmountpoint, METH_VARARGS,
 	 "get filesystem mount point (best-effort)\n"},
 #endif