Mercurial > hg
comparison mercurial/dirstate.py @ 49310:050dc8730858
py3: catch specific OSError subclasses instead of checking errno
Contrary to the previous changesets in this series, this covers cases where
errno was checked for multiple values.
EACCES -> PermissionError
ENOENT -> FileNotFoundError
ENOTDIR -> NotADirectoryError
EISDIR -> IsADirectoryError
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Wed, 01 Jun 2022 00:47:25 +0200 |
parents | 2e726c934fcd |
children | 0043c7aa3250 |
comparison
equal
deleted
inserted
replaced
49309:d54b213c4380 | 49310:050dc8730858 |
---|---|
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 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 |
15 | 14 |
16 from .i18n import _ | 15 from .i18n import _ |
1033 if nd != b'': | 1032 if nd != b'': |
1034 skip = b'.hg' | 1033 skip = b'.hg' |
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 |
1048 # and is not an exactmatcher. This is acceptable; we do not | 1045 # and is not an exactmatcher. This is acceptable; we do not |
1049 # make any hard assumptions about file-or-directory below | 1046 # make any hard assumptions about file-or-directory below |