From ef355a6e06f687e7526b562e13365adcc1079ad5 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Mon, 20 Mar 2017 16:34:12 -0700 Subject: [PATCH] osutil: export a "getfstype" method This patch exports the "getfstype" method. So we can use it to enable hardlinks for known safe filesystems. The patch was tested manually via debugshell on a Linux system. "mercurial.osutil.getfstype" works as expected. It's hard to mount filesystem on user-space easily. I will add a test for real hardlink support to indirectly test this patch, after turning on real hardlinks support for certain whitelisted filesystems. --- mercurial/osutil.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mercurial/osutil.c b/mercurial/osutil.c index bf9381dbf6..cf1f01b0f5 100644 --- a/mercurial/osutil.c +++ b/mercurial/osutil.c @@ -1079,6 +1079,20 @@ const char *getfstype(const char *path) { /* End of Linux filesystems */ return NULL; } + +static PyObject *pygetfstype(PyObject *self, PyObject *args) +{ + const char *path = NULL; + if (!PyArg_ParseTuple(args, "s", &path)) + return NULL; + + const char *type = getfstype(path); + if (type == NULL) + Py_RETURN_NONE; + + PyObject *result = Py_BuildValue("s", type); + return result; +} #endif /* def HAVE_STATFS */ #endif /* ndef _WIN32 */ @@ -1257,6 +1271,10 @@ static PyMethodDef methods[] = { {"setprocname", (PyCFunction)setprocname, METH_VARARGS, "set process title (best-effort)\n"}, #endif +#ifdef HAVE_STATFS + {"getfstype", (PyCFunction)pygetfstype, METH_VARARGS, + "get filesystem type (best-effort)\n"}, +#endif #endif /* ndef _WIN32 */ #ifdef __APPLE__ {