use std::io;
use std::path::Path;
use crate::stats::CloneBackend;
#[cfg(target_os = "macos")]
mod apfs;
#[cfg(any(target_os = "linux", target_os = "android", windows))]
mod reflink;
#[cfg(not(any(
target_os = "macos",
target_os = "linux",
target_os = "android",
windows
)))]
mod unsupported;
pub trait BlockCloner {
fn backend(&self) -> CloneBackend;
fn clone_file(&self, source: &Path, destination: &Path) -> io::Result<()>;
fn clone_directory(&self, source: &Path, destination: &Path) -> io::Result<()>;
fn clones_directories(&self) -> bool;
}
pub fn for_this_platform() -> Box<dyn BlockCloner> {
#[cfg(target_os = "macos")]
{
Box::new(apfs::Clonefile)
}
#[cfg(any(target_os = "linux", target_os = "android"))]
{
Box::new(reflink::Reflink::new(CloneBackend::Ficlone))
}
#[cfg(windows)]
{
Box::new(reflink::Reflink::new(CloneBackend::Refs))
}
#[cfg(not(any(
target_os = "macos",
target_os = "linux",
target_os = "android",
windows
)))]
{
Box::new(unsupported::Unsupported)
}
}