# HG changeset patch # User Georges Racinet # Date 1705498018 -3600 # Node ID 187c5769a62974307e1ab0ff4129c23277e2957b # Parent bc88aa7472de09075c81523cef941ea801483357 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. diff -r bc88aa7472de -r 187c5769a629 mercurial/util.py --- a/mercurial/util.py Sat Nov 26 12:23:56 2022 +0100 +++ b/mercurial/util.py Wed Jan 17 14:26:58 2024 +0100 @@ -2610,12 +2610,16 @@ pass -def tryunlink(f: bytes) -> None: - """Attempt to remove a file, ignoring FileNotFoundError.""" +def tryunlink(f: bytes) -> bool: + """Attempt to remove a file, ignoring FileNotFoundError. + + Returns False in case the file did not exit, True otherwise + """ try: unlink(f) + return True except FileNotFoundError: - pass + return False def makedirs( diff -r bc88aa7472de -r 187c5769a629 mercurial/vfs.py --- a/mercurial/vfs.py Sat Nov 26 12:23:56 2022 +0100 +++ b/mercurial/vfs.py Wed Jan 17 14:26:58 2024 +0100 @@ -303,7 +303,7 @@ def tryunlink(self, path: Optional[bytes] = None): """Attempt to remove a file, ignoring missing file errors.""" - util.tryunlink(self.join(path)) + return util.tryunlink(self.join(path)) def unlinkpath( self, path: Optional[bytes] = None, ignoremissing=False, rmdir=True