##// END OF EJS Templates
typing: avoid some useless @overload definitions in `mercurial.util`...
Matt Harbison -
r52613:e618a175 default
parent child Browse files
Show More
@@ -386,20 +386,20 b' def checkosfilename(path: bytes) -> Opti'
386 return None # on posix platforms, every path is ok
386 return None # on posix platforms, every path is ok
387
387
388
388
389 def getfsmountpoint(dirpath: bytes) -> Optional[bytes]:
389 def getfsmountpoint(path: bytes) -> Optional[bytes]:
390 """Get the filesystem mount point from a directory (best-effort)
390 """Get the filesystem mount point from a directory (best-effort)
391
391
392 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
392 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
393 """
393 """
394 return getattr(osutil, 'getfsmountpoint', lambda x: None)(dirpath)
394 return getattr(osutil, 'getfsmountpoint', lambda x: None)(path)
395
395
396
396
397 def getfstype(dirpath: bytes) -> Optional[bytes]:
397 def getfstype(path: bytes) -> Optional[bytes]:
398 """Get the filesystem type name from a directory (best-effort)
398 """Get the filesystem type name from a directory (best-effort)
399
399
400 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
400 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc.
401 """
401 """
402 return getattr(osutil, 'getfstype', lambda x: None)(dirpath)
402 return getattr(osutil, 'getfstype', lambda x: None)(path)
403
403
404
404
405 def get_password() -> bytes:
405 def get_password() -> bytes:
@@ -691,7 +691,7 b' def makedir(path: bytes, notindexed: boo'
691
691
692 def lookupreg(
692 def lookupreg(
693 key: bytes,
693 key: bytes,
694 name: Optional[bytes] = None,
694 valname: Optional[bytes] = None,
695 scope: Optional[Union[int, Iterable[int]]] = None,
695 scope: Optional[Union[int, Iterable[int]]] = None,
696 ) -> Optional[bytes]:
696 ) -> Optional[bytes]:
697 return None
697 return None
@@ -460,10 +460,10 b' def nlinks(name: bytes) -> int:'
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
@@ -471,10 +471,10 b' def samefile(path1: bytes, path2: bytes)'
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
@@ -711,16 +711,16 b' def spawndetached(args: List[bytes]) -> '
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
@@ -741,9 +741,9 b' def unlink(f: bytes) -> None:'
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
@@ -620,10 +620,10 b' def groupname(gid: Optional[int] = None)'
620 return None
620 return None
621
621
622
622
623 def readlink(pathname: bytes) -> bytes:
623 def readlink(path: bytes) -> bytes:
624 path = pycompat.fsdecode(pathname)
624 path_str = pycompat.fsdecode(path)
625 try:
625 try:
626 link = os.readlink(path)
626 link = os.readlink(path_str)
627 except ValueError as e:
627 except ValueError as e:
628 # On py2, os.readlink() raises an AttributeError since it is
628 # On py2, os.readlink() raises an AttributeError since it is
629 # unsupported. On py3, reading a non-link raises a ValueError. Simply
629 # unsupported. On py3, reading a non-link raises a ValueError. Simply
General Comments 0
You need to be logged in to leave comments. Login now