diff --git a/crates/disktree-core/src/scan.rs b/crates/disktree-core/src/scan.rs index 693253a7..f7ffaeb5 100644 --- a/crates/disktree-core/src/scan.rs +++ b/crates/disktree-core/src/scan.rs @@ -1647,7 +1647,14 @@ mod tests { state.to_le_bytes()[0] }) .collect(); - fs::write(temp.path().join("data.bin"), noise).expect("write"); + // Flush and sync before scanning: on CoW filesystems with delayed + // allocation (such as OpenZFS), asynchronous writes remain buffered + // in transaction groups and report st_blocks = 1 until synced. + let mut file = + fs::File::create(temp.path().join("data.bin")).expect("create"); + std::io::Write::write_all(&mut file, &noise).expect("write"); + file.sync_all().expect("sync"); + drop(file); let tree = scan_dir(temp.path(), &ScanOptions::default()); assert!(tree.bytes >= 100_000, "{}", tree.bytes); assert_eq!(tree.bytes % 512, 0, "{}", tree.bytes);