fix: correct blocks() calculation and remove dead code#219
Draft
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Draft
fix: correct blocks() calculation and remove dead code#219Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Conversation
Contributor
|
Failure from CI |
Contributor
Author
Rebase: fix: correct blocks() calculation and remove dead codeBranch Actions
Automated by Kōan |
Koan-Bot
added a commit
to atoomic/Test-MockFile
that referenced
this pull request
Feb 24, 2026
The blocks() method had two bugs: - Dead code: `int($blocks) > $blocks` was always false since $blocks was already the result of int(), making the guard a no-op - Off-by-one: `int(size/blksize + 1)` unconditionally added 1, causing empty files to report 1 block instead of 0, and files at exact blksize boundaries to over-count Replace with standard ceiling division: int((size + blksize - 1) / blksize) Add t/blocks.t with coverage for edge cases: empty files, small files, exact boundaries, boundary+1, custom blksize, and stat() integration.
28e8ce8 to
da6c1d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix two bugs in the
blocks()method that calculates stat[12] for mocked files.Why
int($blocks) > $blockswas always false —$blockswas alreadyint()'d, soint()of an integer equals itself. The entire if-block was a no-op since the method was written.int(size/blksize + 1)unconditionally adds 1, so empty files report 1 block instead of 0, and files at exact blksize boundaries over-count (e.g., a 4096-byte file with 4096 blksize returned 2 instead of 1).How
Replace with standard ceiling division:
int((size + blksize - 1) / blksize), with an early return of 0 for empty/non-existent files.Testing
New
t/blocks.t(13 tests) covers: empty files, small files, exact boundaries, boundary+1, double boundaries, custom blksize, stat() integration, and directories.🤖 Generated with Claude Code