changeset 31678:1ed57a7dd904

statfs: make getfstype() raise OSError It's better for getfstype() function to not suppress an error. Callers can handle it as necessary. Now "hg debugfsinfo" will report OSError.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 25 Mar 2017 17:25:23 +0900
parents 58d4622bc1ef
children 0f8ba0bc1154
files mercurial/osutil.c mercurial/util.py tests/hghave.py
diffstat 3 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/osutil.c	Sat Mar 25 17:24:11 2017 +0900
+++ b/mercurial/osutil.c	Sat Mar 25 17:25:23 2017 +0900
@@ -1106,7 +1106,7 @@
 	memset(&buf, 0, sizeof(buf));
 	r = statfs(path, &buf);
 	if (r != 0)
-		Py_RETURN_NONE;
+		return PyErr_SetFromErrno(PyExc_OSError);
 	return Py_BuildValue("s", describefstype(&buf));
 }
 #endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */
--- a/mercurial/util.py	Sat Mar 25 17:24:11 2017 +0900
+++ b/mercurial/util.py	Sat Mar 25 17:25:23 2017 +0900
@@ -1089,7 +1089,10 @@
     if hardlink:
         # Hardlinks are problematic on CIFS (issue4546), do not allow hardlinks
         # unless we are confident that dest is on a whitelisted filesystem.
-        fstype = getfstype(os.path.dirname(dest))
+        try:
+            fstype = getfstype(os.path.dirname(dest))
+        except OSError:
+            fstype = None
         if fstype not in _hardlinkfswhitelist:
             hardlink = False
     if hardlink:
@@ -1372,7 +1375,7 @@
 def getfstype(dirpath):
     '''Get the filesystem type name from a directory (best-effort)
 
-    Returns None if we are unsure, or errors like ENOENT, EPERM happen.
+    Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
     '''
     return getattr(osutil, 'getfstype', lambda x: None)(dirpath)
 
--- a/tests/hghave.py	Sat Mar 25 17:24:11 2017 +0900
+++ b/tests/hghave.py	Sat Mar 25 17:25:23 2017 +0900
@@ -349,7 +349,10 @@
 @check("hardlink-whitelisted", "hardlinks on whitelisted filesystems")
 def has_hardlink_whitelisted():
     from mercurial import util
-    fstype = util.getfstype('.')
+    try:
+        fstype = util.getfstype('.')
+    except OSError:
+        return False
     return fstype in util._hardlinkfswhitelist
 
 @check("rmcwd", "can remove current working directory")