From 04a92a8fb3358ad7a386d3b33aacff877cc7b169 Mon Sep 17 00:00:00 2001 From: Kartik Dua Date: Sun, 6 Apr 2025 22:26:04 +0530 Subject: [PATCH] Fix: Use div_ceil with proper blocks computation Fixes: ##523 --- src/find/matchers/printf.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/find/matchers/printf.rs b/src/find/matchers/printf.rs index c7b6e19..deadb45 100644 --- a/src/find/matchers/printf.rs +++ b/src/find/matchers/printf.rs @@ -390,23 +390,18 @@ fn format_directive<'entry>( FormatDirective::Blocks { large_blocks } => { #[cfg(unix)] - let blocks = meta()?.blocks(); + let len = meta()?.blocks() * STANDARD_BLOCK_SIZE; #[cfg(not(unix))] - // Estimate using a ceiling division by the block size. - let blocks = (meta()?.len() + STANDARD_BLOCK_SIZE - 1) / STANDARD_BLOCK_SIZE; + let len = meta()?.len(); // GNU find says it returns the number of 512-byte blocks for %b, // but in reality it just returns the number of blocks, *regardless // of their size on the filesystem*. That behavior is copied here, // even though it's arguably not 100% correct. - if *large_blocks { - // Ceiling divide in half. - blocks.div_ceil(2) - } else { - blocks - } - .to_string() - .into() + let bs = if *large_blocks {1024} else {512}; + let blocks = len.div_ceil(bs); + + blocks.to_string().into() } #[cfg(not(unix))]