Skip to content
Snippets Groups Projects
Commit 4e451d1359de authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

copyfile: allow optional hardlinking

Some code paths use 'copyfiles' (full tree) for a single file to take advantage
of the best-effort-hard-linking parameter. We add similar parameter and logic
to 'copyfile' (single file) for this purpose.

The single file version have the advantage to overwrite the destination file if
it exists.
parent b21c2e0ee8a3
No related branches found
No related tags found
No related merge requests found
......@@ -716,7 +716,7 @@
return check
def copyfile(src, dest):
def copyfile(src, dest, hardlink=False):
"copy a file, preserving mode and atime/mtime"
if os.path.lexists(dest):
unlink(dest)
......@@ -720,6 +720,12 @@
"copy a file, preserving mode and atime/mtime"
if os.path.lexists(dest):
unlink(dest)
if hardlink:
try:
oslink(src, dest)
return
except (IOError, OSError):
pass # fall back to normal copy
if os.path.islink(src):
os.symlink(os.readlink(src), dest)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment