comparison mercurial/win32.py @ 39762:edaa40dc5fe5

py3: create built in exceptions with str type messages in win32.py I hit an IOError in unlink() in test-pathconflicts-basic.t, that then crashed as it was handled: File "mercurial\dispatch.py", line 359, in _runcatch return _callcatch(ui, _runcatchfunc) File "mercurial\dispatch.py", line 367, in _callcatch return scmutil.callcatch(ui, func) File "mercurial\scmutil.py", line 252, in callcatch ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) File "mercurial\encoding.py", line 205, in unitolocal return tolocal(u.encode('utf-8')) AttributeError: 'bytes' object has no attribute 'encode'
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 21 Sep 2018 21:44:27 -0400
parents 255d1885c7f8
children 24e493ec2229
comparison
equal deleted inserted replaced
39761:4675c122157e 39762:edaa40dc5fe5
305 # See https://bugs.python.org/issue28474 305 # See https://bugs.python.org/issue28474
306 code = _kernel32.GetLastError() 306 code = _kernel32.GetLastError()
307 if code > 0x7fffffff: 307 if code > 0x7fffffff:
308 code -= 2**32 308 code -= 2**32
309 err = ctypes.WinError(code=code) 309 err = ctypes.WinError(code=code)
310 raise OSError(err.errno, '%s: %s' % (name, 310 raise OSError(err.errno, r'%s: %s' % (encoding.strfromlocal(name),
311 encoding.strtolocal(err.strerror))) 311 err.strerror))
312 312
313 def _getfileinfo(name): 313 def _getfileinfo(name):
314 fh = _kernel32.CreateFileA(name, 0, 314 fh = _kernel32.CreateFileA(name, 0,
315 _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE, 315 _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,
316 None, _OPEN_EXISTING, _FILE_FLAG_BACKUP_SEMANTICS, None) 316 None, _OPEN_EXISTING, _FILE_FLAG_BACKUP_SEMANTICS, None)
595 595
596 if os.path.isdir(f): 596 if os.path.isdir(f):
597 # use EPERM because it is POSIX prescribed value, even though 597 # use EPERM because it is POSIX prescribed value, even though
598 # unlink(2) on directories returns EISDIR on Linux 598 # unlink(2) on directories returns EISDIR on Linux
599 raise IOError(errno.EPERM, 599 raise IOError(errno.EPERM,
600 "Unlinking directory not permitted: '%s'" % f) 600 r"Unlinking directory not permitted: '%s'"
601 % encoding.strfromlocal(f))
601 602
602 # POSIX allows to unlink and rename open files. Windows has serious 603 # POSIX allows to unlink and rename open files. Windows has serious
603 # problems with doing that: 604 # problems with doing that:
604 # - Calling os.unlink (or os.rename) on a file f fails if f or any 605 # - Calling os.unlink (or os.rename) on a file f fails if f or any
605 # hardlinked copy of f has been opened with Python's open(). There is no 606 # hardlinked copy of f has been opened with Python's open(). There is no
623 break 624 break
624 except OSError as e: 625 except OSError as e:
625 if e.errno != errno.EEXIST: 626 if e.errno != errno.EEXIST:
626 raise 627 raise
627 else: 628 else:
628 raise IOError(errno.EEXIST, "No usable temporary filename found") 629 raise IOError(errno.EEXIST, r"No usable temporary filename found")
629 630
630 try: 631 try:
631 os.unlink(temp) 632 os.unlink(temp)
632 except OSError: 633 except OSError:
633 # The unlink might have failed because the READONLY attribute may heave 634 # The unlink might have failed because the READONLY attribute may heave