##// END OF EJS Templates
py3: catch specific OSError subclasses instead of checking errno...
Manuel Jacob -
r50205:050dc873 default
parent child Browse files
Show More
@@ -8,7 +8,6 b''
8
8
9 import collections
9 import collections
10 import contextlib
10 import contextlib
11 import errno
12 import os
11 import os
13 import stat
12 import stat
14 import uuid
13 import uuid
@@ -1035,13 +1034,11 b' class dirstate:'
1035 try:
1034 try:
1036 with tracing.log('dirstate.walk.traverse listdir %s', nd):
1035 with tracing.log('dirstate.walk.traverse listdir %s', nd):
1037 entries = listdir(join(nd), stat=True, skip=skip)
1036 entries = listdir(join(nd), stat=True, skip=skip)
1038 except OSError as inst:
1037 except (PermissionError, FileNotFoundError) as inst:
1039 if inst.errno in (errno.EACCES, errno.ENOENT):
1038 match.bad(
1040 match.bad(
1039 self.pathto(nd), encoding.strtolocal(inst.strerror)
1041 self.pathto(nd), encoding.strtolocal(inst.strerror)
1040 )
1042 )
1041 continue
1043 continue
1044 raise
1045 for f, kind, st in entries:
1042 for f, kind, st in entries:
1046 # Some matchers may return files in the visitentries set,
1043 # Some matchers may return files in the visitentries set,
1047 # instead of 'this', if the matcher explicitly mentions them
1044 # instead of 'this', if the matcher explicitly mentions them
@@ -6,7 +6,6 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8
8
9 import errno
10 import re
9 import re
11
10
12 from .i18n import _
11 from .i18n import _
@@ -575,16 +574,14 b' class matchctx:'
575 return False
574 return False
576 try:
575 try:
577 return predfn(fctx)
576 return predfn(fctx)
578 except (IOError, OSError) as e:
577 # open()-ing a directory fails with PermissionError on Windows
579 # open()-ing a directory fails with EACCES on Windows
578 except (
580 if e.errno in (
579 FileNotFoundError,
581 errno.ENOENT,
580 PermissionError,
582 errno.EACCES,
581 NotADirectoryError,
583 errno.ENOTDIR,
582 IsADirectoryError,
584 errno.EISDIR,
583 ):
585 ):
584 return False
586 return False
587 raise
588
585
589 else:
586 else:
590
587
@@ -38,9 +38,8 b' def _getlockprefix():'
38 if pycompat.sysplatform.startswith(b'linux'):
38 if pycompat.sysplatform.startswith(b'linux'):
39 try:
39 try:
40 result += b'/%x' % os.stat(b'/proc/self/ns/pid').st_ino
40 result += b'/%x' % os.stat(b'/proc/self/ns/pid').st_ino
41 except OSError as ex:
41 except (FileNotFoundError, PermissionError, NotADirectoryError):
42 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR):
42 pass
43 raise
44 return result
43 return result
45
44
46
45
@@ -581,9 +581,7 b' def statfiles(files):'
581 st = lstat(nf)
581 st = lstat(nf)
582 if getkind(st.st_mode) not in _wantedkinds:
582 if getkind(st.st_mode) not in _wantedkinds:
583 st = None
583 st = None
584 except OSError as err:
584 except (FileNotFoundError, NotADirectoryError):
585 if err.errno not in (errno.ENOENT, errno.ENOTDIR):
586 raise
587 st = None
585 st = None
588 yield st
586 yield st
589
587
@@ -95,7 +95,6 b' else:'
95 ispypy = "PyPy" in sys.version
95 ispypy = "PyPy" in sys.version
96
96
97 import ctypes
97 import ctypes
98 import errno
99 import stat, subprocess, time
98 import stat, subprocess, time
100 import re
99 import re
101 import shutil
100 import shutil
@@ -1422,15 +1421,12 b' class RustExtension(Extension):'
1422 )
1421 )
1423 try:
1422 try:
1424 subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir)
1423 subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir)
1425 except OSError as exc:
1424 except FileNotFoundError:
1426 if exc.errno == errno.ENOENT:
1425 raise RustCompilationError("Cargo not found")
1427 raise RustCompilationError("Cargo not found")
1426 except PermissionError:
1428 elif exc.errno == errno.EACCES:
1427 raise RustCompilationError(
1429 raise RustCompilationError(
1428 "Cargo found, but permission to execute it is denied"
1430 "Cargo found, but permission to execute it is denied"
1429 )
1431 )
1432 else:
1433 raise
1434 except subprocess.CalledProcessError:
1430 except subprocess.CalledProcessError:
1435 raise RustCompilationError(
1431 raise RustCompilationError(
1436 "Cargo failed. Working directory: %r, "
1432 "Cargo failed. Working directory: %r, "
General Comments 0
You need to be logged in to leave comments. Login now