# HG changeset patch # User Manuel Jacob # Date 1654024577 -7200 # Node ID 53e9422a9b45351dbb11fc3ab468f88692e3aa87 # Parent 48f1b314056b4c85bbfc14159bc9c4bc6eb3d142 py3: catch FileExistsError instead of checking errno == EEXIST diff -r 48f1b314056b -r 53e9422a9b45 hgext/mq.py --- a/hgext/mq.py Tue May 31 16:54:58 2022 +0200 +++ b/hgext/mq.py Tue May 31 21:16:17 2022 +0200 @@ -2151,8 +2151,8 @@ raise error.Abort(_(b"patch queue directory already exists")) try: os.mkdir(self.path) - except OSError as inst: - if inst.errno != errno.EEXIST or not create: + except FileExistsError: + if not create: raise if create: return self.qrepo(create=True) diff -r 48f1b314056b -r 53e9422a9b45 hgext/remotefilelog/remotefilelogserver.py --- a/hgext/remotefilelog/remotefilelogserver.py Tue May 31 16:54:58 2022 +0200 +++ b/hgext/remotefilelog/remotefilelogserver.py Tue May 31 21:16:17 2022 +0200 @@ -5,7 +5,6 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -import errno import os import stat import time @@ -255,9 +254,8 @@ if not os.path.exists(dirname): try: os.makedirs(dirname) - except OSError as ex: - if ex.errno != errno.EEXIST: - raise + except FileExistsError: + pass f = None try: diff -r 48f1b314056b -r 53e9422a9b45 hgext/remotefilelog/shallowutil.py --- a/hgext/remotefilelog/shallowutil.py Tue May 31 16:54:58 2022 +0200 +++ b/hgext/remotefilelog/shallowutil.py Tue May 31 21:16:17 2022 +0200 @@ -6,7 +6,6 @@ # GNU General Public License version 2 or any later version. import collections -import errno import os import stat import struct @@ -359,9 +358,8 @@ if not os.path.exists(dirname): try: os.makedirs(dirname) - except OSError as ex: - if ex.errno != errno.EEXIST: - raise + except FileExistsError: + pass fd, temp = tempfile.mkstemp(prefix=b'.%s-' % filename, dir=dirname) os.close(fd) @@ -519,9 +517,8 @@ for path in reversed(missingdirs): try: os.mkdir(path) - except OSError as ex: - if ex.errno != errno.EEXIST: - raise + except FileExistsError: + pass for path in missingdirs: setstickygroupdir(path, gid, ui.warn) diff -r 48f1b314056b -r 53e9422a9b45 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Tue May 31 16:54:58 2022 +0200 +++ b/mercurial/cmdutil.py Tue May 31 21:16:17 2022 +0200 @@ -561,9 +561,8 @@ backupdir = repo.vfs.join(b'record-backups') try: os.mkdir(backupdir) - except OSError as err: - if err.errno != errno.EEXIST: - raise + except FileExistsError: + pass try: # backup continues for f in tobackup: diff -r 48f1b314056b -r 53e9422a9b45 mercurial/hg.py --- a/mercurial/hg.py Tue May 31 16:54:58 2022 +0200 +++ b/mercurial/hg.py Tue May 31 21:16:17 2022 +0200 @@ -7,7 +7,6 @@ # GNU General Public License version 2 or any later version. -import errno import os import posixpath import shutil @@ -528,9 +527,8 @@ # lock class requires the directory to exist. try: util.makedir(pooldir, False) - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass poolvfs = vfsmod.vfs(pooldir) basename = os.path.basename(sharepath) @@ -893,13 +891,9 @@ create=True, createopts=createopts, ) - except OSError as inst: - if inst.errno == errno.EEXIST: - cleandir = None - raise error.Abort( - _(b"destination '%s' already exists") % dest - ) - raise + except FileExistsError: + cleandir = None + raise error.Abort(_(b"destination '%s' already exists") % dest) if revs: if not srcpeer.capable(b'lookup'): diff -r 48f1b314056b -r 53e9422a9b45 mercurial/posix.py --- a/mercurial/posix.py Tue May 31 16:54:58 2022 +0200 +++ b/mercurial/posix.py Tue May 31 21:16:17 2022 +0200 @@ -329,11 +329,9 @@ except OSError: unlink(name) return True - except OSError as inst: + except FileExistsError: # link creation might race, try again - if inst.errno == errno.EEXIST: - continue - raise + continue finally: if fd is not None: fd.close() diff -r 48f1b314056b -r 53e9422a9b45 mercurial/win32.py --- a/mercurial/win32.py Tue May 31 16:54:58 2022 +0200 +++ b/mercurial/win32.py Tue May 31 21:16:17 2022 +0200 @@ -735,11 +735,10 @@ for tries in range(10): temp = b'%s-%08x' % (f, random.randint(0, 0xFFFFFFFF)) try: - os.rename(f, temp) # raises OSError EEXIST if temp exists + os.rename(f, temp) break - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass else: raise IOError(errno.EEXIST, "No usable temporary filename found") diff -r 48f1b314056b -r 53e9422a9b45 mercurial/windows.py --- a/mercurial/windows.py Tue May 31 16:54:58 2022 +0200 +++ b/mercurial/windows.py Tue May 31 21:16:17 2022 +0200 @@ -638,9 +638,7 @@ '''atomically rename file src to dst, replacing dst if it exists''' try: os.rename(src, dst) - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: unlink(dst) os.rename(src, dst) diff -r 48f1b314056b -r 53e9422a9b45 tests/run-tests.py --- a/tests/run-tests.py Tue May 31 16:54:58 2022 +0200 +++ b/tests/run-tests.py Tue May 31 21:16:17 2022 +0200 @@ -1099,9 +1099,8 @@ try: os.mkdir(self._threadtmp) - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass name = self._tmpname self._testtmp = os.path.join(self._threadtmp, name) @@ -3277,9 +3276,8 @@ exceptionsdir = os.path.join(self._outputdir, b'exceptions') try: os.makedirs(exceptionsdir) - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass # Remove all existing exception reports. for f in os.listdir(exceptionsdir): @@ -3593,10 +3591,9 @@ try: os.symlink(sysexecutable, mypython) self._createdfiles.append(mypython) - except OSError as err: + except FileExistsError: # child processes may race, which is harmless - if err.errno != errno.EEXIST: - raise + pass elif WINDOWS and not os.getenv('MSYSTEM'): raise AssertionError('cannot run test on Windows without MSYSTEM') else: @@ -3706,9 +3703,8 @@ def makedirs(p): try: os.makedirs(p) - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass makedirs(self._pythondir) makedirs(self._bindir) @@ -3757,9 +3753,8 @@ covdir = os.path.join(self._installdir, b'..', b'coverage') try: os.mkdir(covdir) - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass osenvironb[b'COVERAGE_DIR'] = covdir diff -r 48f1b314056b -r 53e9422a9b45 tests/test-verify-repo-operations.py --- a/tests/test-verify-repo-operations.py Tue May 31 16:54:58 2022 +0200 +++ b/tests/test-verify-repo-operations.py Tue May 31 21:16:17 2022 +0200 @@ -36,7 +36,6 @@ import binascii from contextlib import contextmanager -import errno import pipes import shutil import silenttestrunner @@ -86,9 +85,8 @@ try: os.close(os.open(savefile, os.O_CREAT | os.O_EXCL | os.O_WRONLY)) break - except OSError as e: - if e.errno != errno.EEXIST: - raise + except FileExistsError: + pass assert os.path.exists(savefile) hgrc = os.path.join(".hg", "hgrc")