##// END OF EJS Templates
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob -
r50201:2e726c93 default
parent child Browse files
Show More
@@ -7,7 +7,6 b''
7 7
8 8 import base64
9 9 import datetime
10 import errno
11 10 import os
12 11 import pickle
13 12 import re
@@ -528,9 +527,7 b' class mapfile(dict):'
528 527 return
529 528 try:
530 529 fp = open(self.path, b'rb')
531 except IOError as err:
532 if err.errno != errno.ENOENT:
533 raise
530 except FileNotFoundError:
534 531 return
535 532 for i, line in enumerate(fp):
536 533 line = line.splitlines()[0].rstrip()
@@ -5,7 +5,6 b''
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 import errno
9 8 import os
10 9 import re
11 10 import shutil
@@ -230,10 +229,8 b' class darcs_source(common.converter_sour'
230 229 try:
231 230 data = util.readfile(path)
232 231 mode = os.lstat(path).st_mode
233 except IOError as inst:
234 if inst.errno == errno.ENOENT:
235 return None, None
236 raise
232 except FileNotFoundError:
233 return None, None
237 234 mode = (mode & 0o111) and b'x' or b''
238 235 return data, mode
239 236
@@ -137,9 +137,8 b' class state:'
137 137 def invalidate(self):
138 138 try:
139 139 os.unlink(os.path.join(self._rootdir, b'.hg', b'fsmonitor.state'))
140 except OSError as inst:
141 if inst.errno != errno.ENOENT:
142 raise
140 except FileNotFoundError:
141 pass
143 142 self._identity = util.filestat(None)
144 143
145 144 def setlastclock(self, clock):
@@ -1,5 +1,4 b''
1 1 import contextlib
2 import errno
3 2 import os
4 3
5 4 from mercurial.node import sha1nodeconstants
@@ -318,9 +317,7 b' class gitdirstate:'
318 317 # TODO construct the stat info from the status object?
319 318 try:
320 319 s = os.stat(os.path.join(cwd, path))
321 except OSError as e:
322 if e.errno != errno.ENOENT:
323 raise
320 except FileNotFoundError:
324 321 continue
325 322 r[path] = s
326 323 return r
@@ -90,7 +90,6 b' delete this code at the end of 2020.'
90 90
91 91 import collections
92 92 import contextlib
93 import errno
94 93 import functools
95 94 import logging
96 95 import os
@@ -1307,9 +1306,8 b' def bundle2scratchbranch(op, part):'
1307 1306 finally:
1308 1307 try:
1309 1308 os.unlink(bundlefile)
1310 except OSError as e:
1311 if e.errno != errno.ENOENT:
1312 raise
1309 except FileNotFoundError:
1310 pass
1313 1311
1314 1312 return 1
1315 1313
@@ -13,7 +13,6 b' bookmarks were previously located.'
13 13
14 14
15 15 import collections
16 import errno
17 16 import os
18 17 import weakref
19 18
@@ -140,9 +139,7 b' def _readsharedfeatures(repo):'
140 139 """A set of shared features for this repository"""
141 140 try:
142 141 return set(repo.vfs.read(b'shared').splitlines())
143 except IOError as inst:
144 if inst.errno != errno.ENOENT:
145 raise
142 except FileNotFoundError:
146 143 return set()
147 144
148 145
@@ -9,7 +9,6 b''
9 9 '''High-level command function for lfconvert, plus the cmdtable.'''
10 10
11 11 import binascii
12 import errno
13 12 import os
14 13 import shutil
15 14
@@ -474,10 +473,8 b' def cachelfiles(ui, repo, node, filelist'
474 473 for lfile in lfiles:
475 474 try:
476 475 expectedhash = lfutil.readasstandin(ctx[lfutil.standin(lfile)])
477 except IOError as err:
478 if err.errno == errno.ENOENT:
479 continue # node must be None and standin wasn't found in wctx
480 raise
476 except FileNotFoundError:
477 continue # node must be None and standin wasn't found in wctx
481 478 if not lfutil.findfile(repo, expectedhash):
482 479 toget.append((lfile, expectedhash))
483 480
@@ -63,7 +63,6 b' in the strip extension.'
63 63 '''
64 64
65 65
66 import errno
67 66 import os
68 67 import re
69 68 import shutil
@@ -551,19 +550,15 b' class queue:'
551 550 try:
552 551 lines = self.opener.read(self.statuspath).splitlines()
553 552 return list(parselines(lines))
554 except IOError as e:
555 if e.errno == errno.ENOENT:
556 return []
557 raise
553 except FileNotFoundError:
554 return []
558 555
559 556 @util.propertycache
560 557 def fullseries(self):
561 558 try:
562 559 return self.opener.read(self.seriespath).splitlines()
563 except IOError as e:
564 if e.errno == errno.ENOENT:
565 return []
566 raise
560 except FileNotFoundError:
561 return []
567 562
568 563 @util.propertycache
569 564 def series(self):
@@ -691,9 +686,7 b' class queue:'
691 686 self.activeguards = []
692 687 try:
693 688 guards = self.opener.read(self.guardspath).split()
694 except IOError as err:
695 if err.errno != errno.ENOENT:
696 raise
689 except FileNotFoundError:
697 690 guards = []
698 691 for i, guard in enumerate(guards):
699 692 bad = self.checkguard(guard)
@@ -1140,9 +1133,8 b' class queue:'
1140 1133 for p in patches:
1141 1134 try:
1142 1135 os.unlink(self.join(p))
1143 except OSError as inst:
1144 if inst.errno != errno.ENOENT:
1145 raise
1136 except FileNotFoundError:
1137 pass
1146 1138
1147 1139 qfinished = []
1148 1140 if numrevs:
@@ -15,7 +15,6 b' https://mercurial-scm.org/wiki/RebaseExt'
15 15 '''
16 16
17 17
18 import errno
19 18 import os
20 19
21 20 from mercurial.i18n import _
@@ -1940,9 +1939,7 b' def restorecollapsemsg(repo, isabort):'
1940 1939 f = repo.vfs(b"last-message.txt")
1941 1940 collapsemsg = f.readline().strip()
1942 1941 f.close()
1943 except IOError as err:
1944 if err.errno != errno.ENOENT:
1945 raise
1942 except FileNotFoundError:
1946 1943 if isabort:
1947 1944 # Oh well, just abort like normal
1948 1945 collapsemsg = b''
@@ -13,7 +13,6 b' process simpler by automating it.'
13 13
14 14
15 15 import difflib
16 import errno
17 16 import re
18 17
19 18 from mercurial.i18n import _
@@ -688,10 +687,7 b' def releasenotes(ui, repo, file_=None, *'
688 687 try:
689 688 with open(file_, b'rb') as fh:
690 689 notes = parsereleasenotesfile(sections, fh.read())
691 except IOError as e:
692 if e.errno != errno.ENOENT:
693 raise
694
690 except FileNotFoundError:
695 691 notes = parsedreleasenotes()
696 692
697 693 notes.merge(ui, incoming)
@@ -166,9 +166,8 b' class basepackstore:'
166 166 )
167 167 else:
168 168 ids.add(id)
169 except OSError as ex:
170 if ex.errno != errno.ENOENT:
171 raise
169 except FileNotFoundError:
170 pass
172 171
173 172 def _getavailablepackfilessorted(self):
174 173 """Like `_getavailablepackfiles`, but also sorts the files by mtime,
@@ -1,4 +1,3 b''
1 import errno
2 1 import os
3 2 import shutil
4 3 import stat
@@ -344,10 +343,7 b' class basestore:'
344 343 count += 1
345 344 try:
346 345 pathstat = os.stat(path)
347 except OSError as e:
348 # errno.ENOENT = no such file or directory
349 if e.errno != errno.ENOENT:
350 raise
346 except FileNotFoundError:
351 347 msg = _(
352 348 b"warning: file %s was removed by another process\n"
353 349 )
@@ -362,10 +358,7 b' class basestore:'
362 358 else:
363 359 try:
364 360 shallowutil.unlinkfile(path)
365 except OSError as e:
366 # errno.ENOENT = no such file or directory
367 if e.errno != errno.ENOENT:
368 raise
361 except FileNotFoundError:
369 362 msg = _(
370 363 b"warning: file %s was removed by another "
371 364 b"process\n"
@@ -388,10 +381,7 b' class basestore:'
388 381 atime, oldpath, oldpathstat = queue.get()
389 382 try:
390 383 shallowutil.unlinkfile(oldpath)
391 except OSError as e:
392 # errno.ENOENT = no such file or directory
393 if e.errno != errno.ENOENT:
394 raise
384 except FileNotFoundError:
395 385 msg = _(
396 386 b"warning: file %s was removed by another process\n"
397 387 )
@@ -66,7 +66,6 b' The following ``share.`` config options '
66 66 '''
67 67
68 68
69 import errno
70 69 from mercurial.i18n import _
71 70 from mercurial import (
72 71 bookmarks,
@@ -177,9 +176,7 b' def _hassharedbookmarks(repo):'
177 176 return False
178 177 try:
179 178 shared = repo.vfs.read(b'shared').splitlines()
180 except IOError as inst:
181 if inst.errno != errno.ENOENT:
182 raise
179 except FileNotFoundError:
183 180 return False
184 181 return hg.sharedbookmarks in shared
185 182
@@ -199,9 +196,8 b' def getbkfile(orig, repo):'
199 196 # is up-to-date.
200 197 return fp
201 198 fp.close()
202 except IOError as inst:
203 if inst.errno != errno.ENOENT:
204 raise
199 except FileNotFoundError:
200 pass
205 201
206 202 # otherwise, we should read bookmarks from srcrepo,
207 203 # because .hg/bookmarks in srcrepo might be already
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 9 import struct
11 10
12 11 from .i18n import _
@@ -114,9 +113,8 b' class bmstore:'
114 113 _(b'malformed line in %s: %r\n')
115 114 % (bookmarkspath, pycompat.bytestr(line))
116 115 )
117 except IOError as inst:
118 if inst.errno != errno.ENOENT:
119 raise
116 except FileNotFoundError:
117 pass
120 118 self._active = _readactive(repo, self)
121 119
122 120 @property
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 9 import os
11 10 import re
12 11 import sys
@@ -6175,9 +6174,8 b' def resolve(ui, repo, *pats, **opts):'
6175 6174 a = repo.wjoin(f)
6176 6175 try:
6177 6176 util.copyfile(a, a + b".resolve")
6178 except (IOError, OSError) as inst:
6179 if inst.errno != errno.ENOENT:
6180 raise
6177 except FileNotFoundError:
6178 pass
6181 6179
6182 6180 try:
6183 6181 # preresolve file
@@ -6194,9 +6192,8 b' def resolve(ui, repo, *pats, **opts):'
6194 6192 util.rename(
6195 6193 a + b".resolve", scmutil.backuppath(ui, repo, f)
6196 6194 )
6197 except OSError as inst:
6198 if inst.errno != errno.ENOENT:
6199 raise
6195 except FileNotFoundError:
6196 pass
6200 6197
6201 6198 if hasconflictmarkers:
6202 6199 ui.warn(
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 9 import filecmp
11 10 import os
12 11 import stat
@@ -1737,9 +1736,7 b' class workingctx(committablectx):'
1737 1736 def copy(self, source, dest):
1738 1737 try:
1739 1738 st = self._repo.wvfs.lstat(dest)
1740 except OSError as err:
1741 if err.errno != errno.ENOENT:
1742 raise
1739 except FileNotFoundError:
1743 1740 self._repo.ui.warn(
1744 1741 _(b"%s does not exist!\n") % self._repo.dirstate.pathto(dest)
1745 1742 )
@@ -2169,9 +2166,7 b' class workingfilectx(committablefilectx)'
2169 2166 t, tz = self._changectx.date()
2170 2167 try:
2171 2168 return (self._repo.wvfs.lstat(self._path)[stat.ST_MTIME], tz)
2172 except OSError as err:
2173 if err.errno != errno.ENOENT:
2174 raise
2169 except FileNotFoundError:
2175 2170 return (t, tz)
2176 2171
2177 2172 def exists(self):
@@ -2350,9 +2350,8 b' def debuglocks(ui, repo, **opts):'
2350 2350 )
2351 2351 ui.writenoi18n(b"%-6s %s (%ds)\n" % (name + b":", locker, age))
2352 2352 return 1
2353 except OSError as e:
2354 if e.errno != errno.ENOENT:
2355 raise
2353 except FileNotFoundError:
2354 pass
2356 2355
2357 2356 ui.writenoi18n(b"%-6s free\n" % (name + b":"))
2358 2357 return 0
@@ -195,9 +195,7 b' class dirstate:'
195 195 def _branch(self):
196 196 try:
197 197 return self._opener.read(b"branch").strip() or b"default"
198 except IOError as inst:
199 if inst.errno != errno.ENOENT:
200 raise
198 except FileNotFoundError:
201 199 return b"default"
202 200
203 201 @property
@@ -4,8 +4,6 b''
4 4 # GNU General Public License version 2 or any later version.
5 5
6 6
7 import errno
8
9 7 from .i18n import _
10 8
11 9 from . import (
@@ -95,9 +93,7 b' class _dirstatemapcommon:'
95 93 try:
96 94 with self._opendirstatefile() as fp:
97 95 return fp.read(size)
98 except IOError as err:
99 if err.errno != errno.ENOENT:
100 raise
96 except FileNotFoundError:
101 97 # File doesn't exist, so the current state is empty
102 98 return b''
103 99
@@ -7,7 +7,6 b''
7 7
8 8
9 9 import difflib
10 import errno
11 10
12 11 from .i18n import _
13 12
@@ -158,9 +157,8 b' class grepsearcher:'
158 157 fctx = ctx[fn]
159 158 try:
160 159 return fctx.data()
161 except IOError as e:
162 if e.errno != errno.ENOENT:
163 raise
160 except FileNotFoundError:
161 pass
164 162 else:
165 163 flog = self._getfile(fn)
166 164 fnode = ctx.filenode(fn)
@@ -7,7 +7,6 b''
7 7 # GNU General Public License version 2 or any later version.
8 8
9 9
10 import errno
11 10 import functools
12 11 import os
13 12 import random
@@ -517,7 +516,7 b' def _readrequires(vfs, allowmissing):'
517 516 """reads the require file present at root of this vfs
518 517 and return a set of requirements
519 518
520 If allowmissing is True, we suppress ENOENT if raised"""
519 If allowmissing is True, we suppress FileNotFoundError if raised"""
521 520 # requires file contains a newline-delimited list of
522 521 # features/capabilities the opener (us) must have in order to use
523 522 # the repository. This file was introduced in Mercurial 0.9.2,
@@ -525,8 +524,8 b' def _readrequires(vfs, allowmissing):'
525 524 # a missing file translates to no requirements.
526 525 try:
527 526 requirements = set(vfs.read(b'requires').splitlines())
528 except IOError as e:
529 if not (allowmissing and e.errno == errno.ENOENT):
527 except FileNotFoundError:
528 if not allowmissing:
530 529 raise
531 530 requirements = set()
532 531 return requirements
@@ -583,9 +582,8 b' def makelocalrepository(baseui, path, in'
583 582 if not hgvfs.isdir():
584 583 try:
585 584 hgvfs.stat()
586 except OSError as e:
587 if e.errno != errno.ENOENT:
588 raise
585 except FileNotFoundError:
586 pass
589 587 except ValueError as e:
590 588 # Can be raised on Python 3.8 when path is invalid.
591 589 raise error.Abort(
@@ -3503,9 +3501,8 b' def aftertrans(files):'
3503 3501 vfs.tryunlink(dest)
3504 3502 try:
3505 3503 vfs.rename(src, dest)
3506 except OSError as exc: # journal file does not yet exist
3507 if exc.errno != errno.ENOENT:
3508 raise
3504 except FileNotFoundError: # journal file does not yet exist
3505 pass
3509 3506
3510 3507 return a
3511 3508
@@ -311,10 +311,8 b' class lock:'
311 311 """
312 312 try:
313 313 return self.vfs.readlock(self.f)
314 except (OSError, IOError) as why:
315 if why.errno == errno.ENOENT:
316 return None
317 raise
314 except FileNotFoundError:
315 return None
318 316
319 317 def _lockshouldbebroken(self, locker):
320 318 if locker is None:
@@ -7,7 +7,6 b''
7 7
8 8
9 9 import collections
10 import errno
11 10 import struct
12 11
13 12 from .i18n import _
@@ -1306,10 +1305,8 b' def calculateupdates('
1306 1305 def _getcwd():
1307 1306 try:
1308 1307 return encoding.getcwd()
1309 except OSError as err:
1310 if err.errno == errno.ENOENT:
1311 return None
1312 raise
1308 except FileNotFoundError:
1309 return None
1313 1310
1314 1311
1315 1312 def batchremove(repo, wctx, actions):
@@ -1,5 +1,4 b''
1 1 import collections
2 import errno
3 2 import shutil
4 3 import struct
5 4 import weakref
@@ -629,9 +628,8 b' class mergestate(_mergestate_base):'
629 628 else:
630 629 records.append((RECORD_MERGED, l[:-1]))
631 630 f.close()
632 except IOError as err:
633 if err.errno != errno.ENOENT:
634 raise
631 except FileNotFoundError:
632 pass
635 633 return records
636 634
637 635 def _readrecordsv2(self):
@@ -669,9 +667,8 b' class mergestate(_mergestate_base):'
669 667 rtype, record = record[0:1], record[1:]
670 668 records.append((rtype, record))
671 669 f.close()
672 except IOError as err:
673 if err.errno != errno.ENOENT:
674 raise
670 except FileNotFoundError:
671 pass
675 672 return records
676 673
677 674 def commit(self):
@@ -69,7 +69,6 b' comment associated with each format for '
69 69 """
70 70
71 71 import binascii
72 import errno
73 72 import struct
74 73
75 74 from .i18n import _
@@ -582,11 +581,10 b' class obsstore:'
582 581 if not self._cached('_all'):
583 582 try:
584 583 return self.svfs.stat(b'obsstore').st_size > 1
585 except OSError as inst:
586 if inst.errno != errno.ENOENT:
587 raise
584 except FileNotFoundError:
588 585 # just build an empty _all list if no obsstore exists, which
589 586 # avoids further stat() syscalls
587 pass
590 588 return bool(self._all)
591 589
592 590 __bool__ = __nonzero__
@@ -10,7 +10,6 b''
10 10 import collections
11 11 import contextlib
12 12 import copy
13 import errno
14 13 import os
15 14 import re
16 15 import shutil
@@ -503,14 +502,11 b' class fsbackend(abstractbackend):'
503 502 isexec = False
504 503 try:
505 504 isexec = self.opener.lstat(fname).st_mode & 0o100 != 0
506 except OSError as e:
507 if e.errno != errno.ENOENT:
508 raise
505 except FileNotFoundError:
506 pass
509 507 try:
510 508 return (self.opener.read(fname), (False, isexec))
511 except IOError as e:
512 if e.errno != errno.ENOENT:
513 raise
509 except FileNotFoundError:
514 510 return None, None
515 511
516 512 def setfile(self, fname, data, mode, copysource):
@@ -101,7 +101,6 b' Note: old client behave as a publishing '
101 101 """
102 102
103 103
104 import errno
105 104 import struct
106 105
107 106 from .i18n import _
@@ -202,9 +201,7 b' def _readroots(repo, phasedefaults=None)'
202 201 roots[int(phase)].add(bin(nh))
203 202 finally:
204 203 f.close()
205 except IOError as inst:
206 if inst.errno != errno.ENOENT:
207 raise
204 except FileNotFoundError:
208 205 if phasedefaults:
209 206 for f in phasedefaults:
210 207 roots = f(repo, roots)
@@ -175,9 +175,7 b' def copymode(src, dst, mode=None, enforc'
175 175 using umask."""
176 176 try:
177 177 st_mode = os.lstat(src).st_mode & 0o777
178 except OSError as inst:
179 if inst.errno != errno.ENOENT:
180 raise
178 except FileNotFoundError:
181 179 st_mode = mode
182 180 if st_mode is None:
183 181 st_mode = ~umask
@@ -226,19 +224,16 b' def checkexec(path):'
226 224
227 225 try:
228 226 m = os.stat(checkisexec).st_mode
229 except OSError as e:
230 if e.errno != errno.ENOENT:
231 raise
227 except FileNotFoundError:
232 228 # checkisexec does not exist - fall through ...
229 pass
233 230 else:
234 231 # checkisexec exists, check if it actually is exec
235 232 if m & EXECFLAGS != 0:
236 233 # ensure checkisexec exists, check it isn't exec
237 234 try:
238 235 m = os.stat(checknoexec).st_mode
239 except OSError as e:
240 if e.errno != errno.ENOENT:
241 raise
236 except FileNotFoundError:
242 237 open(checknoexec, b'w').close() # might fail
243 238 m = os.stat(checknoexec).st_mode
244 239 if m & EXECFLAGS == 0:
@@ -16,7 +16,6 b' and O(changes) merge between branches.'
16 16 import binascii
17 17 import collections
18 18 import contextlib
19 import errno
20 19 import io
21 20 import os
22 21 import struct
@@ -486,9 +485,7 b' class revlog:'
486 485 return fp.read()
487 486 else:
488 487 return fp.read(size)
489 except IOError as inst:
490 if inst.errno != errno.ENOENT:
491 raise
488 except FileNotFoundError:
492 489 return b''
493 490
494 491 def _loadindex(self, docket=None):
@@ -701,9 +698,7 b' class revlog:'
701 698 else:
702 699 f.seek(self._docket.index_end, os.SEEK_SET)
703 700 return f
704 except IOError as inst:
705 if inst.errno != errno.ENOENT:
706 raise
701 except FileNotFoundError:
707 702 return self.opener(
708 703 self._indexfile, mode=b"w+", checkambig=self._checkambig
709 704 )
@@ -2116,9 +2111,7 b' class revlog:'
2116 2111 dfh.seek(0, os.SEEK_END)
2117 2112 else:
2118 2113 dfh.seek(self._docket.data_end, os.SEEK_SET)
2119 except IOError as inst:
2120 if inst.errno != errno.ENOENT:
2121 raise
2114 except FileNotFoundError:
2122 2115 dfh = self._datafp(b"w+")
2123 2116 transaction.add(self._datafile, dsize)
2124 2117 if self._sidedatafile is not None:
@@ -2127,9 +2120,7 b' class revlog:'
2127 2120 try:
2128 2121 sdfh = self.opener(self._sidedatafile, mode=b"r+")
2129 2122 dfh.seek(self._docket.sidedata_end, os.SEEK_SET)
2130 except IOError as inst:
2131 if inst.errno != errno.ENOENT:
2132 raise
2123 except FileNotFoundError:
2133 2124 sdfh = self.opener(self._sidedatafile, mode=b"w+")
2134 2125 transaction.add(
2135 2126 self._sidedatafile, self._docket.sidedata_end
@@ -2832,9 +2823,7 b' class revlog:'
2832 2823 f.seek(0, io.SEEK_END)
2833 2824 actual = f.tell()
2834 2825 dd = actual - expected
2835 except IOError as inst:
2836 if inst.errno != errno.ENOENT:
2837 raise
2826 except FileNotFoundError:
2838 2827 dd = 0
2839 2828
2840 2829 try:
@@ -2851,9 +2840,7 b' class revlog:'
2851 2840 databytes += max(0, self.length(r))
2852 2841 dd = 0
2853 2842 di = actual - len(self) * s - databytes
2854 except IOError as inst:
2855 if inst.errno != errno.ENOENT:
2856 raise
2843 except FileNotFoundError:
2857 2844 di = 0
2858 2845
2859 2846 return (dd, di)
@@ -16,7 +16,6 b''
16 16 # * a data file, containing variable width data for these revisions,
17 17
18 18
19 import errno
20 19 import os
21 20 import random
22 21 import struct
@@ -51,9 +50,7 b' if stable_docket_file:'
51 50 try:
52 51 with open(stable_docket_file, mode='rb') as f:
53 52 seed = f.read().strip()
54 except IOError as inst:
55 if inst.errno != errno.ENOENT:
56 raise
53 except FileNotFoundError:
57 54 seed = b'04' # chosen by a fair dice roll. garanteed to be random
58 55 iter_seed = iter(seed)
59 56 # some basic circular sum hashing on 64 bits
@@ -7,7 +7,6 b''
7 7 # GNU General Public License version 2 or any later version.
8 8
9 9
10 import errno
11 10 import re
12 11 import struct
13 12
@@ -83,11 +82,8 b' def persisted_data(revlog):'
83 82 data = b''
84 83 else:
85 84 data = fd.read(data_length)
86 except (IOError, OSError) as e:
87 if e.errno == errno.ENOENT:
88 return None
89 else:
90 raise
85 except FileNotFoundError:
86 return None
91 87 if len(data) < data_length:
92 88 return None
93 89 return docket, data
@@ -1619,9 +1619,8 b' class filecachesubentry:'
1619 1619 def stat(path):
1620 1620 try:
1621 1621 return util.cachestat(path)
1622 except OSError as e:
1623 if e.errno != errno.ENOENT:
1624 raise
1622 except FileNotFoundError:
1623 pass
1625 1624
1626 1625
1627 1626 class filecacheentry:
@@ -22,7 +22,6 b' shelve".'
22 22 """
23 23
24 24 import collections
25 import errno
26 25 import itertools
27 26 import stat
28 27
@@ -82,9 +81,7 b' class ShelfDir:'
82 81 """return all shelves in repo as list of (time, name)"""
83 82 try:
84 83 names = self.vfs.listdir()
85 except OSError as err:
86 if err.errno != errno.ENOENT:
87 raise
84 except FileNotFoundError:
88 85 return []
89 86 info = []
90 87 seen = set()
@@ -724,9 +721,7 b' def _loadshelvedstate(ui, repo, opts):'
724 721 state = shelvedstate.load(repo)
725 722 if opts.get(b'keep') is None:
726 723 opts[b'keep'] = state.keep
727 except IOError as err:
728 if err.errno != errno.ENOENT:
729 raise
724 except FileNotFoundError:
730 725 cmdutil.wrongtooltocontinue(repo, _(b'unshelve'))
731 726 except error.CorruptedState as err:
732 727 ui.debug(pycompat.bytestr(err) + b'\n')
@@ -181,9 +181,7 b' class statichttprepository('
181 181
182 182 try:
183 183 requirements = set(self.vfs.read(b'requires').splitlines())
184 except IOError as inst:
185 if inst.errno != errno.ENOENT:
186 raise
184 except FileNotFoundError:
187 185 requirements = set()
188 186
189 187 # check if it is a non-empty old-style repository
@@ -191,9 +189,7 b' class statichttprepository('
191 189 fp = self.vfs(b"00changelog.i")
192 190 fp.read(1)
193 191 fp.close()
194 except IOError as inst:
195 if inst.errno != errno.ENOENT:
196 raise
192 except FileNotFoundError:
197 193 # we do not care about empty old-style repositories here
198 194 msg = _(b"'%s' does not appear to be an hg repository") % path
199 195 raise error.RepoError(msg)
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 9 import functools
11 10 import os
12 11 import re
@@ -788,9 +787,8 b' class fncachestore(basicstore):'
788 787 assert t is not None, f
789 788 t |= FILEFLAGS_FILELOG
790 789 yield t, f, self.getsize(ef)
791 except OSError as err:
792 if err.errno != errno.ENOENT:
793 raise
790 except FileNotFoundError:
791 pass
794 792
795 793 def copylist(self):
796 794 d = (
@@ -825,10 +823,7 b' class fncachestore(basicstore):'
825 823 try:
826 824 self.getsize(ef)
827 825 return True
828 except OSError as err:
829 if err.errno != errno.ENOENT:
830 raise
831 # nonexistent entry
826 except FileNotFoundError:
832 827 return False
833 828
834 829 def __contains__(self, path):
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 9 import os
11 10 import posixpath
12 11 import re
@@ -63,9 +62,7 b' def state(ctx, ui):'
63 62 if f in ctx:
64 63 try:
65 64 data = ctx[f].data()
66 except IOError as err:
67 if err.errno != errno.ENOENT:
68 raise
65 except FileNotFoundError:
69 66 # handle missing subrepo spec files as removed
70 67 ui.warn(
71 68 _(b"warning: subrepo spec file \'%s\' not found\n")
@@ -102,9 +99,8 b' def state(ctx, ui):'
102 99 % (repo.pathto(b'.hgsubstate'), (i + 1))
103 100 )
104 101 rev[path] = revision
105 except IOError as err:
106 if err.errno != errno.ENOENT:
107 raise
102 except FileNotFoundError:
103 pass
108 104
109 105 def remap(src):
110 106 # type: (bytes) -> bytes
@@ -12,7 +12,6 b''
12 12
13 13
14 14 import binascii
15 import errno
16 15 import io
17 16
18 17 from .node import (
@@ -242,9 +241,7 b' def readlocaltags(ui, repo, alltags, tag'
242 241 '''Read local tags in repo. Update alltags and tagtypes.'''
243 242 try:
244 243 data = repo.vfs.read(b"localtags")
245 except IOError as inst:
246 if inst.errno != errno.ENOENT:
247 raise
244 except FileNotFoundError:
248 245 return
249 246
250 247 # localtags is in the local encoding; re-encode to UTF-8 on
@@ -652,9 +649,7 b' def _tag('
652 649
653 650 try:
654 651 fp = repo.wvfs(b'.hgtags', b'rb+')
655 except IOError as e:
656 if e.errno != errno.ENOENT:
657 raise
652 except FileNotFoundError:
658 653 fp = repo.wvfs(b'.hgtags', b'ab')
659 654 else:
660 655 prevtags = fp.read()
@@ -12,8 +12,6 b''
12 12 # GNU General Public License version 2 or any later version.
13 13
14 14
15 import errno
16
17 15 from .i18n import _
18 16 from . import (
19 17 error,
@@ -71,9 +69,8 b' def _playback('
71 69 else:
72 70 try:
73 71 opener.unlink(f)
74 except (IOError, OSError) as inst:
75 if inst.errno != errno.ENOENT:
76 raise
72 except FileNotFoundError:
73 pass
77 74
78 75 backupfiles = []
79 76 for l, f, b, c in backupentries:
@@ -95,9 +92,8 b' def _playback('
95 92 target = f or b
96 93 try:
97 94 vfs.unlink(target)
98 except (IOError, OSError) as inst:
99 if inst.errno != errno.ENOENT:
100 raise
95 except FileNotFoundError:
96 pass
101 97 except (IOError, OSError, error.Abort):
102 98 if not c:
103 99 raise
@@ -6,8 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10
11 9 from . import encoding
12 10
13 11
@@ -29,7 +27,6 b' def trypending(root, vfs, filename, **kw'
29 27 if mayhavepending(root):
30 28 try:
31 29 return (vfs(b'%s.pending' % filename, **kwargs), True)
32 except IOError as inst:
33 if inst.errno != errno.ENOENT:
34 raise
30 except FileNotFoundError:
31 pass
35 32 return (vfs(filename, **kwargs), False)
@@ -1517,8 +1517,8 b' class ui:'
1517 1517 stderr=procutil.stderr,
1518 1518 env=procutil.tonativeenv(procutil.shellenviron(env)),
1519 1519 )
1520 except OSError as e:
1521 if e.errno == errno.ENOENT and not shell:
1520 except FileNotFoundError:
1521 if not shell:
1522 1522 self.warn(
1523 1523 _(b"missing pager command '%s', skipping pager\n") % command
1524 1524 )
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8
9 import errno
10 9 import stat
11 10
12 11 from ..i18n import _
@@ -646,11 +645,10 b' def upgrade_dirstate(ui, srcrepo, upgrad'
646 645 util.copyfile(
647 646 srcrepo.vfs.join(b'dirstate'), backupvfs.join(b'dirstate')
648 647 )
649 except (IOError, OSError) as e:
648 except FileNotFoundError:
650 649 # The dirstate does not exist on an empty repo or a repo with no
651 650 # revision checked out
652 if e.errno != errno.ENOENT:
653 raise
651 pass
654 652
655 653 assert srcrepo.dirstate._use_dirstate_v2 == (old == b'v2')
656 654 srcrepo.dirstate._map.preload()
@@ -659,11 +657,10 b' def upgrade_dirstate(ui, srcrepo, upgrad'
659 657 srcrepo.dirstate._dirty = True
660 658 try:
661 659 srcrepo.vfs.unlink(b'dirstate')
662 except (IOError, OSError) as e:
660 except FileNotFoundError:
663 661 # The dirstate does not exist on an empty repo or a repo with no
664 662 # revision checked out
665 if e.errno != errno.ENOENT:
666 raise
663 pass
667 664
668 665 srcrepo.dirstate.write(None)
669 666
@@ -2426,9 +2426,7 b' class filestat:'
2426 2426 def frompath(cls, path):
2427 2427 try:
2428 2428 stat = os.stat(path)
2429 except OSError as err:
2430 if err.errno != errno.ENOENT:
2431 raise
2429 except FileNotFoundError:
2432 2430 stat = None
2433 2431 return cls(stat)
2434 2432
@@ -2612,12 +2610,11 b' def unlinkpath(f, ignoremissing=False, r'
2612 2610
2613 2611 def tryunlink(f):
2614 2612 # type: (bytes) -> None
2615 """Attempt to remove a file, ignoring ENOENT errors."""
2613 """Attempt to remove a file, ignoring FileNotFoundError."""
2616 2614 try:
2617 2615 unlink(f)
2618 except OSError as e:
2619 if e.errno != errno.ENOENT:
2620 raise
2616 except FileNotFoundError:
2617 pass
2621 2618
2622 2619
2623 2620 def makedirs(name, mode=None, notindexed=False):
@@ -6,7 +6,6 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 import contextlib
9 import errno
10 9 import os
11 10 import shutil
12 11 import stat
@@ -74,18 +73,16 b' class abstractvfs:'
74 73 '''gracefully return an empty string for missing files'''
75 74 try:
76 75 return self.read(path)
77 except IOError as inst:
78 if inst.errno != errno.ENOENT:
79 raise
76 except FileNotFoundError:
77 pass
80 78 return b""
81 79
82 80 def tryreadlines(self, path, mode=b'rb'):
83 81 '''gracefully return an empty array for missing files'''
84 82 try:
85 83 return self.readlines(path, mode=mode)
86 except IOError as inst:
87 if inst.errno != errno.ENOENT:
88 raise
84 except FileNotFoundError:
85 pass
89 86 return []
90 87
91 88 @util.propertycache
@@ -476,9 +473,7 b' class vfs(abstractvfs):'
476 473 nlink = util.nlinks(f)
477 474 if nlink < 1:
478 475 nlink = 2 # force mktempcopy (issue1922)
479 except (OSError, IOError) as e:
480 if e.errno != errno.ENOENT:
481 raise
476 except FileNotFoundError:
482 477 nlink = 0
483 478 if makeparentdirs:
484 479 util.makedirs(dirname, self.createmode, notindexed)
@@ -362,9 +362,7 b' def parselistfiles(files, listtype, warn'
362 362 try:
363 363 path = os.path.expanduser(os.path.expandvars(filename))
364 364 f = open(path, "rb")
365 except IOError as err:
366 if err.errno != errno.ENOENT:
367 raise
365 except FileNotFoundError:
368 366 if warn:
369 367 print("warning: no such %s file: %s" % (listtype, filename))
370 368 continue
@@ -390,9 +388,8 b' def parsettestcases(path):'
390 388 for l in f:
391 389 if l.startswith(b'#testcases '):
392 390 cases.append(sorted(l[11:].split()))
393 except IOError as ex:
394 if ex.errno != errno.ENOENT:
395 raise
391 except FileNotFoundError:
392 pass
396 393 return cases
397 394
398 395
@@ -1110,12 +1107,11 b' class Test(unittest.TestCase):'
1110 1107 if os.path.exists(self.errpath):
1111 1108 try:
1112 1109 os.remove(self.errpath)
1113 except OSError as e:
1114 # We might have raced another test to clean up a .err
1115 # file, so ignore ENOENT when removing a previous .err
1110 except FileNotFoundError:
1111 # We might have raced another test to clean up a .err file,
1112 # so ignore FileNotFoundError when removing a previous .err
1116 1113 # file.
1117 if e.errno != errno.ENOENT:
1118 raise
1114 pass
1119 1115
1120 1116 if self._usechg:
1121 1117 self._chgsockdir = os.path.join(
@@ -2622,9 +2618,8 b' def loadtimes(outputdir):'
2622 2618 times.append(
2623 2619 (m.group(1), [float(t) for t in m.group(2).split()])
2624 2620 )
2625 except IOError as err:
2626 if err.errno != errno.ENOENT:
2627 raise
2621 except FileNotFoundError:
2622 pass
2628 2623 return times
2629 2624
2630 2625
@@ -2979,9 +2974,7 b' def sorttests(testdescs, previoustimes, '
2979 2974 except KeyError:
2980 2975 try:
2981 2976 val = -os.stat(f).st_size
2982 except OSError as e:
2983 if e.errno != errno.ENOENT:
2984 raise
2977 except FileNotFoundError:
2985 2978 perf[f] = -1e9 # file does not exist, tell early
2986 2979 return -1e9
2987 2980 for kw, mul in slow.items():
@@ -3584,9 +3577,8 b' class TestRunner:'
3584 3577 if os.readlink(mypython) == sysexecutable:
3585 3578 continue
3586 3579 os.unlink(mypython)
3587 except OSError as err:
3588 if err.errno != errno.ENOENT:
3589 raise
3580 except FileNotFoundError:
3581 pass
3590 3582 if self._findprogram(pyexename) != sysexecutable:
3591 3583 try:
3592 3584 os.symlink(sysexecutable, mypython)
@@ -3714,9 +3706,8 b' class TestRunner:'
3714 3706 if not self.options.verbose:
3715 3707 try:
3716 3708 os.remove(installerrs)
3717 except OSError as e:
3718 if e.errno != errno.ENOENT:
3719 raise
3709 except FileNotFoundError:
3710 pass
3720 3711 else:
3721 3712 with open(installerrs, 'rb') as f:
3722 3713 for line in f:
@@ -58,9 +58,8 b' A set of extension and shell functions e'
58 58 > def delete():
59 59 > try:
60 60 > os.unlink(watchpath)
61 > except OSError as exc:
62 > if exc.errno != errno.ENOENT:
63 > raise
61 > except FileNotFoundError:
62 > pass
64 63 > ui.atexit(delete)
65 64 > return orig(pushop)
66 65 >
General Comments 0
You need to be logged in to leave comments. Login now