Expand description
A library for efficiently cloning directory trees with copy-on-write support.
This crate provides functionality to clone entire directory structures while leveraging filesystem-level copy-on-write (CoW) capabilities when available through reflinks. This can result in significant space savings and improved performance compared to traditional file copying.
§Features
- Copy-on-Write Support: Automatically uses reflinks when available on supported filesystems (Btrfs, XFS, APFS, etc.)
- Glob Filtering: Include or exclude files using glob patterns
- Efficient Traversal: Built on the
ignore
crate for fast directory walking - Type-Safe Errors: Comprehensive error handling with descriptive error types
§Example
use clonetree::{clone_tree, Options};
// Clone a directory tree
let options = Options::new();
clone_tree("/source/path", "/destination/path", &options)?;
// Clone with glob filters
let options = Options::new()
.glob("**/*.rs") // Include only Rust files
.glob("!target/**"); // Exclude target directory
clone_tree("/source", "/dest", &options)?;
// Clone with overwrite enabled
let options = Options::new()
.overwrite(true); // Allow overwriting existing files
clone_tree("/source", "/existing_dest", &options)?;
§Validation
The clone_tree
function enforces the following constraints:
- Source path must exist and be a directory
- Destination path must not exist (unless
overwrite
option is enabled)
These constraints are validated before any filesystem operations begin.