Mercurial > hg-stable
comparison mercurial/vfs.py @ 50750:f173c2c23289 stable
vfs: handle shutil.rmtree deprecation of onerror in Python 3.12
Tests would fail with warnings:
.../mercurial/vfs.py:289: DeprecationWarning: onerror argument is deprecated, use onexc instead
The excinfo changed slightly, but we don't use it anyway.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Tue, 27 Jun 2023 08:39:12 +0200 |
parents | d1d458fb96a5 |
children | 18c8c18993f0 |
comparison
equal
deleted
inserted
replaced
50749:a2df74853f8d | 50750:f173c2c23289 |
---|---|
272 | 272 |
273 If ``forcibly``, this tries to remove READ-ONLY files, too. | 273 If ``forcibly``, this tries to remove READ-ONLY files, too. |
274 """ | 274 """ |
275 if forcibly: | 275 if forcibly: |
276 | 276 |
277 def onerror(function, path, excinfo): | 277 def onexc(function, path, excinfo): |
278 if function is not os.remove: | 278 if function is not os.remove: |
279 raise | 279 raise |
280 # read-only files cannot be unlinked under Windows | 280 # read-only files cannot be unlinked under Windows |
281 s = os.stat(path) | 281 s = os.stat(path) |
282 if (s.st_mode & stat.S_IWRITE) != 0: | 282 if (s.st_mode & stat.S_IWRITE) != 0: |
283 raise | 283 raise |
284 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) | 284 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) |
285 os.remove(path) | 285 os.remove(path) |
286 | 286 |
287 else: | 287 else: |
288 onerror = None | 288 onexc = None |
289 return shutil.rmtree( | 289 try: |
290 self.join(path), ignore_errors=ignore_errors, onerror=onerror | 290 # pytype: disable=wrong-keyword-args |
291 ) | 291 return shutil.rmtree( |
292 self.join(path), ignore_errors=ignore_errors, onexc=onexc | |
293 ) | |
294 # pytype: enable=wrong-keyword-args | |
295 except TypeError: # onexc was introduced in Python 3.12 | |
296 return shutil.rmtree( | |
297 self.join(path), ignore_errors=ignore_errors, onerror=onexc | |
298 ) | |
292 | 299 |
293 def setflags(self, path: bytes, l: bool, x: bool): | 300 def setflags(self, path: bytes, l: bool, x: bool): |
294 return util.setflags(self.join(path), l, x) | 301 return util.setflags(self.join(path), l, x) |
295 | 302 |
296 def stat(self, path: Optional[bytes] = None): | 303 def stat(self, path: Optional[bytes] = None): |