[go: up one dir, main page]

pub fn reflink_or_copy(
    from: impl AsRef<Path>,
    to: impl AsRef<Path>
) -> Result<Option<u64>>
Expand description

Attempts to reflink a file. If the operation fails, a conventional copy operation is attempted as a fallback.

If the function reflinked a file, the return value will be Ok(None).

If the function copied a file, the return value will be Ok(Some(written)).

match reflink_copy::reflink_or_copy("src.txt", "dest.txt") {
    Ok(None) => println!("file has been reflinked"),
    Ok(Some(written)) => println!("file has been copied ({} bytes)", written),
    Err(e) => println!("an error occured: {:?}", e)
}

Implementation details per platform

MacOS / OS X / iOS

If src names a directory, the directory hierarchy is cloned as if each item was cloned individually. This method does not provide a fallback for directories, so the fallback will also fail if reflinking failed. Macos supports reflinking symlinks, which is supported by the fallback.