# HG changeset patch # User Pierre-Yves David # Date 2021-06-08 00:31:17 # Node ID d756fc11cfb9deba8f7191995ef42807c53090db # Parent 2f4ca4807033a9d1b3c5dd63bf441e9c26fbc5fe copyfile: add a option callback for failed hardlinking Local clone, adjust its UI depending on the success of using hardlinking, so we add a small callback making it possible for `copyfile` to signal if the requested hardlinking failed. Differential Revision: https://phab.mercurial-scm.org/D10853 diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1910,7 +1910,13 @@ def checksignature(func, depth=1): def copyfile( - src, dest, hardlink=False, copystat=False, checkambig=False, nb_bytes=None + src, + dest, + hardlink=False, + copystat=False, + checkambig=False, + nb_bytes=None, + no_hardlink_cb=None, ): """copy a file, preserving mode and optionally other stat info like atime/mtime @@ -1937,6 +1943,8 @@ def copyfile( except OSError: fstype = None if fstype not in _hardlinkfswhitelist: + if no_hardlink_cb is not None: + no_hardlink_cb() hardlink = False if hardlink: try: @@ -1945,8 +1953,10 @@ def copyfile( m = "the `nb_bytes` argument is incompatible with `hardlink`" raise error.ProgrammingError(m) return - except (IOError, OSError): - pass # fall back to normal copy + except (IOError, OSError) as exc: + if exc.errno != errno.EEXIST and no_hardlink_cb is not None: + no_hardlink_cb() + # fall back to normal copy if os.path.islink(src): os.symlink(os.readlink(src), dest) # copytime is ignored for symlinks, but in general copytime isn't needed