comparison mercurial/util.py @ 51427:187c5769a629

vfs: have tryunlink tell what it did It is useful in certain circumstances to know whether vfs.tryunlink() actually removed something or not, be it for logging purposes.
author Georges Racinet <georges.racinet@octobus.net>
date Wed, 17 Jan 2024 14:26:58 +0100
parents c8a2fdf5ca37
children a452807df09b 6c39edd1d348
comparison
equal deleted inserted replaced
51426:bc88aa7472de 51427:187c5769a629
2608 removedirs(os.path.dirname(f)) 2608 removedirs(os.path.dirname(f))
2609 except OSError: 2609 except OSError:
2610 pass 2610 pass
2611 2611
2612 2612
2613 def tryunlink(f: bytes) -> None: 2613 def tryunlink(f: bytes) -> bool:
2614 """Attempt to remove a file, ignoring FileNotFoundError.""" 2614 """Attempt to remove a file, ignoring FileNotFoundError.
2615
2616 Returns False in case the file did not exit, True otherwise
2617 """
2615 try: 2618 try:
2616 unlink(f) 2619 unlink(f)
2620 return True
2617 except FileNotFoundError: 2621 except FileNotFoundError:
2618 pass 2622 return False
2619 2623
2620 2624
2621 def makedirs( 2625 def makedirs(
2622 name: bytes, mode: Optional[int] = None, notindexed: bool = False 2626 name: bytes, mode: Optional[int] = None, notindexed: bool = False
2623 ) -> None: 2627 ) -> None: