Show More
@@ -1909,7 +1909,9 b' def checksignature(func, depth=1):' | |||||
1909 | } |
|
1909 | } | |
1910 |
|
1910 | |||
1911 |
|
1911 | |||
1912 | def copyfile(src, dest, hardlink=False, copystat=False, checkambig=False): |
|
1912 | def copyfile( | |
|
1913 | src, dest, hardlink=False, copystat=False, checkambig=False, nb_bytes=None | |||
|
1914 | ): | |||
1913 | """copy a file, preserving mode and optionally other stat info like |
|
1915 | """copy a file, preserving mode and optionally other stat info like | |
1914 | atime/mtime |
|
1916 | atime/mtime | |
1915 |
|
1917 | |||
@@ -1918,6 +1920,8 b' def copyfile(src, dest, hardlink=False, ' | |||||
1918 | repo.wlock). |
|
1920 | repo.wlock). | |
1919 |
|
1921 | |||
1920 | copystat and checkambig should be exclusive. |
|
1922 | copystat and checkambig should be exclusive. | |
|
1923 | ||||
|
1924 | nb_bytes: if set only copy the first `nb_bytes` of the source file. | |||
1921 | """ |
|
1925 | """ | |
1922 | assert not (copystat and checkambig) |
|
1926 | assert not (copystat and checkambig) | |
1923 | oldstat = None |
|
1927 | oldstat = None | |
@@ -1937,6 +1941,9 b' def copyfile(src, dest, hardlink=False, ' | |||||
1937 | if hardlink: |
|
1941 | if hardlink: | |
1938 | try: |
|
1942 | try: | |
1939 | oslink(src, dest) |
|
1943 | oslink(src, dest) | |
|
1944 | if nb_bytes is not None: | |||
|
1945 | m = "the `nb_bytes` argument is incompatible with `hardlink`" | |||
|
1946 | raise error.ProgrammingError(m) | |||
1940 | return |
|
1947 | return | |
1941 | except (IOError, OSError): |
|
1948 | except (IOError, OSError): | |
1942 | pass # fall back to normal copy |
|
1949 | pass # fall back to normal copy | |
@@ -1944,6 +1951,9 b' def copyfile(src, dest, hardlink=False, ' | |||||
1944 | os.symlink(os.readlink(src), dest) |
|
1951 | os.symlink(os.readlink(src), dest) | |
1945 | # copytime is ignored for symlinks, but in general copytime isn't needed |
|
1952 | # copytime is ignored for symlinks, but in general copytime isn't needed | |
1946 | # for them anyway |
|
1953 | # for them anyway | |
|
1954 | if nb_bytes is not None: | |||
|
1955 | m = "cannot use `nb_bytes` on a symlink" | |||
|
1956 | raise error.ProgrammingError(m) | |||
1947 | else: |
|
1957 | else: | |
1948 | try: |
|
1958 | try: | |
1949 | shutil.copyfile(src, dest) |
|
1959 | shutil.copyfile(src, dest) | |
@@ -1960,6 +1970,10 b' def copyfile(src, dest, hardlink=False, ' | |||||
1960 | oldstat.stat[stat.ST_MTIME] + 1 |
|
1970 | oldstat.stat[stat.ST_MTIME] + 1 | |
1961 | ) & 0x7FFFFFFF |
|
1971 | ) & 0x7FFFFFFF | |
1962 | os.utime(dest, (advanced, advanced)) |
|
1972 | os.utime(dest, (advanced, advanced)) | |
|
1973 | # We could do something smarter using `copy_file_range` call or similar | |||
|
1974 | if nb_bytes is not None: | |||
|
1975 | with open(dest, mode='r+') as f: | |||
|
1976 | f.truncate(nb_bytes) | |||
1963 | except shutil.Error as inst: |
|
1977 | except shutil.Error as inst: | |
1964 | raise error.Abort(stringutil.forcebytestr(inst)) |
|
1978 | raise error.Abort(stringutil.forcebytestr(inst)) | |
1965 |
|
1979 |
General Comments 0
You need to be logged in to leave comments.
Login now