-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
df: fix block size header for multiples of 1024 #3191
Merged
Merged
Conversation
This file contains 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
jfinkels
commented
Feb 26, 2022
Comment on lines
+155
to
+184
// TODO We have not yet implemented this behavior, but when we do, | ||
// uncomment this test. | ||
|
||
// #[test] | ||
// fn test_to_magnitude_and_suffix_not_powers_of_1024() { | ||
// assert_eq!(to_magnitude_and_suffix(1).unwrap(), "1B"); | ||
// assert_eq!(to_magnitude_and_suffix(999).unwrap(), "999B"); | ||
|
||
// assert_eq!(to_magnitude_and_suffix(1000).unwrap(), "1kB"); | ||
// assert_eq!(to_magnitude_and_suffix(1001).unwrap(), "1.1kB"); | ||
// assert_eq!(to_magnitude_and_suffix(1023).unwrap(), "1.1kB"); | ||
// assert_eq!(to_magnitude_and_suffix(1025).unwrap(), "1.1kB"); | ||
// assert_eq!(to_magnitude_and_suffix(999_000).unwrap(), "999kB"); | ||
|
||
// assert_eq!(to_magnitude_and_suffix(999_001).unwrap(), "1MB"); | ||
// assert_eq!(to_magnitude_and_suffix(999_999).unwrap(), "1MB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_000_000).unwrap(), "1MB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_000_001).unwrap(), "1.1MB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_100_000).unwrap(), "1.1MB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_100_001).unwrap(), "1.2MB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_900_000).unwrap(), "1.9MB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_900_001).unwrap(), "2MB"); | ||
// assert_eq!(to_magnitude_and_suffix(9_900_000).unwrap(), "9.9MB"); | ||
// assert_eq!(to_magnitude_and_suffix(9_900_001).unwrap(), "10MB"); | ||
// assert_eq!(to_magnitude_and_suffix(999_000_000).unwrap(), "999MB"); | ||
|
||
// assert_eq!(to_magnitude_and_suffix(999_000_001).unwrap(), "1GB"); | ||
// assert_eq!(to_magnitude_and_suffix(1_000_000_000).unwrap(), "1GB"); | ||
// // etc. | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some test cases here for the future
ce2b876
to
5e7e05d
Compare
Correct the column header printed by `df` when the `--block-size` argument has a value that is a multiple of 1024. After this commit, the header looks like "1K" or "4M" or "117G", etc., depending on the particular value of the block size. For example: $ df --block-size=1024 | head -n1 Filesystem 1K-blocks Used Available Use% Mounted on $ df --block-size=2048 | head -n1 Filesystem 2K-blocks Used Available Use% Mounted on $ df --block-size=3072 | head -n1 Filesystem 3K-blocks Used Available Use% Mounted on $ df --block-size=4096 | head -n1 Filesystem 4K-blocks Used Available Use% Mounted on
5e7e05d
to
5cf7139
Compare
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.
This pull request corrects the column header printed by
df
when the--block-size
argument has a value that is a multiple of 1024. After this commit, the header looks like "1K" or "4M" or "117G", etc., depending on the particular value of the block size. For example:This matches the behavior of GNU df.
This pull request does not correct the header when the block size is not divisible by 1024. It sets it to "1kB-blocks", which is wrong in all cases except when block size is set to 1000. (Previously, the header was always set to "1k-blocks", which is never a correct column header for GNU df. I figured that changing it to be correct in one case is better than leaving it incorrect in all cases. 🤷 ) A future pull request can fix that.