Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 49306:2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Tue, 31 May 2022 22:50:01 +0200 |
parents | c6a3243567b6 |
children | d2adebe35635 |
comparison
equal
deleted
inserted
replaced
49305:53e9422a9b45 | 49306:2e726c934fcd |
---|---|
2424 | 2424 |
2425 @classmethod | 2425 @classmethod |
2426 def frompath(cls, path): | 2426 def frompath(cls, path): |
2427 try: | 2427 try: |
2428 stat = os.stat(path) | 2428 stat = os.stat(path) |
2429 except OSError as err: | 2429 except FileNotFoundError: |
2430 if err.errno != errno.ENOENT: | |
2431 raise | |
2432 stat = None | 2430 stat = None |
2433 return cls(stat) | 2431 return cls(stat) |
2434 | 2432 |
2435 @classmethod | 2433 @classmethod |
2436 def fromfp(cls, fp): | 2434 def fromfp(cls, fp): |
2610 pass | 2608 pass |
2611 | 2609 |
2612 | 2610 |
2613 def tryunlink(f): | 2611 def tryunlink(f): |
2614 # type: (bytes) -> None | 2612 # type: (bytes) -> None |
2615 """Attempt to remove a file, ignoring ENOENT errors.""" | 2613 """Attempt to remove a file, ignoring FileNotFoundError.""" |
2616 try: | 2614 try: |
2617 unlink(f) | 2615 unlink(f) |
2618 except OSError as e: | 2616 except FileNotFoundError: |
2619 if e.errno != errno.ENOENT: | 2617 pass |
2620 raise | |
2621 | 2618 |
2622 | 2619 |
2623 def makedirs(name, mode=None, notindexed=False): | 2620 def makedirs(name, mode=None, notindexed=False): |
2624 # type: (bytes, Optional[int], bool) -> None | 2621 # type: (bytes, Optional[int], bool) -> None |
2625 """recursive directory creation with parent mode inheritance | 2622 """recursive directory creation with parent mode inheritance |