mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #3347 from cakebaker/fix_total_use_percentage
df: fix calculation of Use% in "total" row
This commit is contained in:
commit
ef8921044b
2 changed files with 8 additions and 4 deletions
|
@ -102,6 +102,7 @@ impl AddAssign for Row {
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
let bytes = self.bytes + rhs.bytes;
|
let bytes = self.bytes + rhs.bytes;
|
||||||
let bytes_used = self.bytes_used + rhs.bytes_used;
|
let bytes_used = self.bytes_used + rhs.bytes_used;
|
||||||
|
let bytes_avail = self.bytes_avail + rhs.bytes_avail;
|
||||||
let inodes = self.inodes + rhs.inodes;
|
let inodes = self.inodes + rhs.inodes;
|
||||||
let inodes_used = self.inodes_used + rhs.inodes_used;
|
let inodes_used = self.inodes_used + rhs.inodes_used;
|
||||||
*self = Self {
|
*self = Self {
|
||||||
|
@ -111,11 +112,14 @@ impl AddAssign for Row {
|
||||||
fs_mount: "-".into(),
|
fs_mount: "-".into(),
|
||||||
bytes,
|
bytes,
|
||||||
bytes_used,
|
bytes_used,
|
||||||
bytes_avail: self.bytes_avail + rhs.bytes_avail,
|
bytes_avail,
|
||||||
bytes_usage: if bytes == 0 {
|
bytes_usage: if bytes == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(bytes_used as f64 / bytes as f64)
|
// We use "(bytes_used + bytes_avail)" instead of "bytes" because on some filesystems (e.g.
|
||||||
|
// ext4) "bytes" also includes reserved blocks we ignore for the usage calculation.
|
||||||
|
// https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#df-Size-and-Used-and-Available-do-not-add-up
|
||||||
|
Some(bytes_used as f64 / (bytes_used + bytes_avail) as f64)
|
||||||
},
|
},
|
||||||
// TODO Figure out how to compute this.
|
// TODO Figure out how to compute this.
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -164,7 +168,7 @@ impl From<Filesystem> for Row {
|
||||||
// We use "(bused + bavail)" instead of "blocks" because on some filesystems (e.g.
|
// We use "(bused + bavail)" instead of "blocks" because on some filesystems (e.g.
|
||||||
// ext4) "blocks" also includes reserved blocks we ignore for the usage calculation.
|
// ext4) "blocks" also includes reserved blocks we ignore for the usage calculation.
|
||||||
// https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#df-Size-and-Used-and-Available-do-not-add-up
|
// https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#df-Size-and-Used-and-Available-do-not-add-up
|
||||||
Some((bused as f64) / (bused + bavail) as f64)
|
Some(bused as f64 / (bused + bavail) as f64)
|
||||||
},
|
},
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
bytes_capacity: if bavail == 0 {
|
bytes_capacity: if bavail == 0 {
|
||||||
|
|
|
@ -140,7 +140,7 @@ fn test_total() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_use_percentage() {
|
fn test_use_percentage() {
|
||||||
let output = new_ucmd!()
|
let output = new_ucmd!()
|
||||||
.args(&["--output=used,avail,pcent"])
|
.args(&["--total", "--output=used,avail,pcent"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_move_str();
|
.stdout_move_str();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue