comparison mercurial/util.py @ 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 080734cd2440
children bf64449b2779
comparison
equal deleted inserted replaced
31677:58d4622bc1ef 31678:1ed57a7dd904
1087 oldstat = checkambig and filestat(dest) 1087 oldstat = checkambig and filestat(dest)
1088 unlink(dest) 1088 unlink(dest)
1089 if hardlink: 1089 if hardlink:
1090 # Hardlinks are problematic on CIFS (issue4546), do not allow hardlinks 1090 # Hardlinks are problematic on CIFS (issue4546), do not allow hardlinks
1091 # unless we are confident that dest is on a whitelisted filesystem. 1091 # unless we are confident that dest is on a whitelisted filesystem.
1092 fstype = getfstype(os.path.dirname(dest)) 1092 try:
1093 fstype = getfstype(os.path.dirname(dest))
1094 except OSError:
1095 fstype = None
1093 if fstype not in _hardlinkfswhitelist: 1096 if fstype not in _hardlinkfswhitelist:
1094 hardlink = False 1097 hardlink = False
1095 if hardlink: 1098 if hardlink:
1096 try: 1099 try:
1097 oslink(src, dest) 1100 oslink(src, dest)
1370 return ''.join(result) 1373 return ''.join(result)
1371 1374
1372 def getfstype(dirpath): 1375 def getfstype(dirpath):
1373 '''Get the filesystem type name from a directory (best-effort) 1376 '''Get the filesystem type name from a directory (best-effort)
1374 1377
1375 Returns None if we are unsure, or errors like ENOENT, EPERM happen. 1378 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
1376 ''' 1379 '''
1377 return getattr(osutil, 'getfstype', lambda x: None)(dirpath) 1380 return getattr(osutil, 'getfstype', lambda x: None)(dirpath)
1378 1381
1379 def checknlink(testfile): 1382 def checknlink(testfile):
1380 '''check whether hardlink count reporting works properly''' 1383 '''check whether hardlink count reporting works properly'''