Skip to content

Fix: Use div_ceil with proper blocks computation - #529

Merged
sylvestre merged 2 commits into
uutils:mainfrom
KartikDua1504:fix-blocks
Apr 10, 2025
Merged

sylvestre merged 2 commits into
uutils:mainfrom
KartikDua1504:fix-blocks

Conversation

@KartikDua1504

@KartikDua1504 KartikDua1504 commented Apr 6, 2025 •

Copy link
Copy Markdown
Contributor

Fixes: #523

@KartikDua1504

Copy link
Copy Markdown
Contributor Author

@sylvestre I have made the changes, but the intention of the code change were not clear to me and were ambiguous in the issue description. Could you please review and let me know if some other changes are required.

@codecov

codecov Bot commented Apr 6, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 87.49%. Comparing base (949bcb8) to head (fa4399b).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/find/matchers/printf.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #529      +/-   ##
==========================================
+ Coverage   87.36%   87.49%   +0.13%     
==========================================
  Files          31       31              
  Lines        6812     6815       +3     
  Branches      321      321              
==========================================
+ Hits         5951     5963      +12     
+ Misses        630      621       -9     
  Partials      231      231              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/find/matchers/printf.rs Outdated
let blocks = {
let blocks = meta()?.blocks();
let len = blocks * STANDARD_BLOCK_SIZE;
let bs = if *large_blocks { 1024 } else { 512 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now wrong as it's dividing the result again by 2 in the next statement. I really meant to replace the whole thing with

FormatDirective::Blocks { large_blocks } => {
    #[cfg(unix)]
    let len = meta()?.blocks() * STANDARD_BLOCK_SIZE;
    #[cfg(not(unix))]
    let len = meta()?.len();

    let bs = if *large_blocks { 1024 } else { 512 };
    blocks.div_ceil(len, bs)
        .to_string()
        .into()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I have made the changes. It's my first time contributing to open-source so i made a mistake. Could you please check it now, and let me know if its correct?

@tavianator tavianator left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong, you're only changing the #[cfg(not(unix))] statement. You need to change the whole match guard

FormatDirective::Blocks { large_blocks } => {
    ...
}

@sylvestre

Copy link
Copy Markdown
Contributor

Please run cargo fmt on it

@KartikDua1504

Copy link
Copy Markdown
Contributor Author

Sir, I formatted the document. Sorry for the inconvenience caused.

@sylvestre
sylvestre merged commit cacb1c1 into uutils:main Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix blocks.div_ceil(len, bs)

3 participants