comparison mercurial/util.py @ 47451:d756fc11cfb9

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
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 08 Jun 2021 02:31:17 +0200
parents 9ea525216edb
children 09ff5d532a25
comparison
equal deleted inserted replaced
47450:2f4ca4807033 47451:d756fc11cfb9
1908 b'zfs', 1908 b'zfs',
1909 } 1909 }
1910 1910
1911 1911
1912 def copyfile( 1912 def copyfile(
1913 src, dest, hardlink=False, copystat=False, checkambig=False, nb_bytes=None 1913 src,
1914 dest,
1915 hardlink=False,
1916 copystat=False,
1917 checkambig=False,
1918 nb_bytes=None,
1919 no_hardlink_cb=None,
1914 ): 1920 ):
1915 """copy a file, preserving mode and optionally other stat info like 1921 """copy a file, preserving mode and optionally other stat info like
1916 atime/mtime 1922 atime/mtime
1917 1923
1918 checkambig argument is used with filestat, and is useful only if 1924 checkambig argument is used with filestat, and is useful only if
1935 try: 1941 try:
1936 fstype = getfstype(os.path.dirname(dest)) 1942 fstype = getfstype(os.path.dirname(dest))
1937 except OSError: 1943 except OSError:
1938 fstype = None 1944 fstype = None
1939 if fstype not in _hardlinkfswhitelist: 1945 if fstype not in _hardlinkfswhitelist:
1946 if no_hardlink_cb is not None:
1947 no_hardlink_cb()
1940 hardlink = False 1948 hardlink = False
1941 if hardlink: 1949 if hardlink:
1942 try: 1950 try:
1943 oslink(src, dest) 1951 oslink(src, dest)
1944 if nb_bytes is not None: 1952 if nb_bytes is not None:
1945 m = "the `nb_bytes` argument is incompatible with `hardlink`" 1953 m = "the `nb_bytes` argument is incompatible with `hardlink`"
1946 raise error.ProgrammingError(m) 1954 raise error.ProgrammingError(m)
1947 return 1955 return
1948 except (IOError, OSError): 1956 except (IOError, OSError) as exc:
1949 pass # fall back to normal copy 1957 if exc.errno != errno.EEXIST and no_hardlink_cb is not None:
1958 no_hardlink_cb()
1959 # fall back to normal copy
1950 if os.path.islink(src): 1960 if os.path.islink(src):
1951 os.symlink(os.readlink(src), dest) 1961 os.symlink(os.readlink(src), dest)
1952 # copytime is ignored for symlinks, but in general copytime isn't needed 1962 # copytime is ignored for symlinks, but in general copytime isn't needed
1953 # for them anyway 1963 # for them anyway
1954 if nb_bytes is not None: 1964 if nb_bytes is not None: