Skip to content

Commit

Permalink
simplify example's code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaiz committed Jan 18, 2025
1 parent 2f0dada commit 7f96c2d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/reflink_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ fn main() -> std::io::Result<()> {

let mut offset = 0u64;
while offset < len {
// Windows API clones the entire cluster regardless of the number of bytes actually used by
// the file in that cluster.
#[cfg(windows)]
let src_length = cluster_size;
#[cfg(not(windows))]
let src_length = NonZeroU64::new(cluster_size.get().min(len - offset)).unwrap();
let src_length = if cfg!(windows) {
// Windows API clones the entire cluster regardless of the number of bytes actually used
// by the file in that cluster.
cluster_size
} else {
cluster_size.min(NonZeroU64::new(len - offset).unwrap())
};

println!("reflink {offset}, {src_length}");
reflink_copy::ReflinkBlockBuilder::new(&from_file, &to_file, src_length)
Expand All @@ -36,7 +37,7 @@ fn main() -> std::io::Result<()> {
.cluster_size(cluster_size)
.reflink_block()?;

offset += cluster_size.get();
offset += src_length.get();
}
Ok(())
}

0 comments on commit 7f96c2d

Please sign in to comment.