Shutil.copy2 reflink

Reflinks (copy-on-write clones) are much faster to create and far more space-efficient on filesystems that support them. (for example XFS, Btrfs, Bcachefs, ZFS, CIFS, NFS, OCFS2, overlayfs, APFS, ReFS. Notable exceptions include Ext4 and NTFS)

GNU Coreutils’s cp use reflinks opportunistically (--reflink=auto) by default as of version 9.0 (2021)

I suggest we bring reflink to shutil.copy2, something like

shutil.copy2(src, dst)               # opportunistically use reflink (default)
shutil.copy2(src, dst, reflink=None) # same as above
shutil.copy2(src, dst, reflink=False)# never use reflink
shutil.copy2(src, dst, reflink=True) # raise OSError if reflink fails
1 Like

There is an issue open since 2019: shutil: add reflink=False to file copy functions to control clone/CoW copies (use copy_file_range) · Issue #81338 · python/cpython · GitHub.

1 Like