Mercurial > public > mercurial-scm > hg
comparison mercurial/win32.py @ 51716:e618a1756b08
typing: avoid some useless @overload definitions in `mercurial.util`
Apparently pytype considered the name as well as the type of each argument, and
generates @overload definitions if they don't match. At best this is clutter,
and can easily be removed.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 19 Jul 2024 16:38:53 -0400 |
parents | ca7bde5dbafb |
children | f4733654f144 |
comparison
equal
deleted
inserted
replaced
51715:7558cee89655 | 51716:e618a1756b08 |
---|---|
458 def nlinks(name: bytes) -> int: | 458 def nlinks(name: bytes) -> int: |
459 '''return number of hardlinks for the given file''' | 459 '''return number of hardlinks for the given file''' |
460 return _getfileinfo(name).nNumberOfLinks | 460 return _getfileinfo(name).nNumberOfLinks |
461 | 461 |
462 | 462 |
463 def samefile(path1: bytes, path2: bytes) -> bool: | 463 def samefile(fpath1: bytes, fpath2: bytes) -> bool: |
464 '''Returns whether path1 and path2 refer to the same file or directory.''' | 464 '''Returns whether fpath1 and fpath2 refer to the same file or directory.''' |
465 res1 = _getfileinfo(path1) | 465 res1 = _getfileinfo(fpath1) |
466 res2 = _getfileinfo(path2) | 466 res2 = _getfileinfo(fpath2) |
467 return ( | 467 return ( |
468 res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber | 468 res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber |
469 and res1.nFileIndexHigh == res2.nFileIndexHigh | 469 and res1.nFileIndexHigh == res2.nFileIndexHigh |
470 and res1.nFileIndexLow == res2.nFileIndexLow | 470 and res1.nFileIndexLow == res2.nFileIndexLow |
471 ) | 471 ) |
472 | 472 |
473 | 473 |
474 def samedevice(path1: bytes, path2: bytes) -> bool: | 474 def samedevice(fpath1: bytes, fpath2: bytes) -> bool: |
475 '''Returns whether path1 and path2 are on the same device.''' | 475 '''Returns whether fpath1 and fpath2 are on the same device.''' |
476 res1 = _getfileinfo(path1) | 476 res1 = _getfileinfo(fpath1) |
477 res2 = _getfileinfo(path2) | 477 res2 = _getfileinfo(fpath2) |
478 return res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber | 478 return res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber |
479 | 479 |
480 | 480 |
481 def peekpipe(pipe) -> int: | 481 def peekpipe(pipe) -> int: |
482 handle = msvcrt.get_osfhandle(pipe.fileno()) # pytype: disable=module-attr | 482 handle = msvcrt.get_osfhandle(pipe.fileno()) # pytype: disable=module-attr |
709 _kernel32.CloseHandle(pi.hThread) | 709 _kernel32.CloseHandle(pi.hThread) |
710 | 710 |
711 return pi.dwProcessId | 711 return pi.dwProcessId |
712 | 712 |
713 | 713 |
714 def unlink(f: bytes) -> None: | 714 def unlink(path: bytes) -> None: |
715 '''try to implement POSIX' unlink semantics on Windows''' | 715 '''try to implement POSIX' unlink semantics on Windows''' |
716 | 716 |
717 if os.path.isdir(f): | 717 if os.path.isdir(path): |
718 # use EPERM because it is POSIX prescribed value, even though | 718 # use EPERM because it is POSIX prescribed value, even though |
719 # unlink(2) on directories returns EISDIR on Linux | 719 # unlink(2) on directories returns EISDIR on Linux |
720 raise IOError( | 720 raise IOError( |
721 errno.EPERM, | 721 errno.EPERM, |
722 r"Unlinking directory not permitted: '%s'" | 722 r"Unlinking directory not permitted: '%s'" |
723 % encoding.strfromlocal(f), | 723 % encoding.strfromlocal(path), |
724 ) | 724 ) |
725 | 725 |
726 # POSIX allows to unlink and rename open files. Windows has serious | 726 # POSIX allows to unlink and rename open files. Windows has serious |
727 # problems with doing that: | 727 # problems with doing that: |
728 # - Calling os.unlink (or os.rename) on a file f fails if f or any | 728 # - Calling os.unlink (or os.rename) on a file f fails if f or any |
739 # f to a random temporary name before calling os.unlink on it. This allows | 739 # f to a random temporary name before calling os.unlink on it. This allows |
740 # callers to recreate f immediately while having other readers do their | 740 # callers to recreate f immediately while having other readers do their |
741 # implicit zombie filename blocking on a temporary name. | 741 # implicit zombie filename blocking on a temporary name. |
742 | 742 |
743 for tries in range(10): | 743 for tries in range(10): |
744 temp = b'%s-%08x' % (f, random.randint(0, 0xFFFFFFFF)) | 744 temp = b'%s-%08x' % (path, random.randint(0, 0xFFFFFFFF)) |
745 try: | 745 try: |
746 os.rename(f, temp) | 746 os.rename(path, temp) |
747 break | 747 break |
748 except FileExistsError: | 748 except FileExistsError: |
749 pass | 749 pass |
750 else: | 750 else: |
751 raise IOError(errno.EEXIST, "No usable temporary filename found") | 751 raise IOError(errno.EEXIST, "No usable temporary filename found") |