pub fn reflink(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()>
Expand description
Copies a file using COW semantics.
For compatibility reasons with macOS, the target file will be created using OpenOptions::create_new
.
If you want to overwrite existing files, make sure you manually delete the target file first
if it exists.
match reflink_copy::reflink("src.txt", "dest.txt") {
Ok(()) => println!("file has been reflinked"),
Err(e) => println!("error while reflinking: {:?}", e)
}
§Implementation details per platform
§Linux / Android
Uses ioctl_ficlone
. Supported file systems include btrfs and XFS (and maybe more in the future).
NOTE that it generates a temporary file and is not atomic.
§MacOS / OS X / iOS
Uses clonefile
library function. This is supported on OS X Version >=10.12 and iOS version >= 10.0
This will work on APFS partitions (which means most desktop systems are capable).
If src names a directory, the directory hierarchy is cloned as if each item was cloned individually.
§Windows
Uses ioctl FSCTL_DUPLICATE_EXTENTS_TO_FILE
.
Supports ReFS on Windows Server and Windows Dev Drives. Important note: The windows implementation is currently untested and probably buggy. Contributions/testers with access to a Windows Server or Dev Drives are welcome. More Information on Dev Drives
NOTE that it generates a temporary file and is not atomic.