From facaabc42ab8dbefd3afd2d447e4f81ce0782a43 Mon Sep 17 00:00:00 2001 From: sylvestre Date: Wed, 1 Jun 2022 04:09:45 +0000 Subject: [PATCH] deploy: c249eba195809b51d95ea470b413d669888f9a27 --- dev/src/uu_df/table.rs.html | 64 +++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/dev/src/uu_df/table.rs.html b/dev/src/uu_df/table.rs.html index 9296d988d..3b8ac2ce7 100644 --- a/dev/src/uu_df/table.rs.html +++ b/dev/src/uu_df/table.rs.html @@ -794,6 +794,24 @@ 789 790 791 +792 +793 +794 +795 +796 +797 +798 +799 +800 +801 +802 +803 +804 +805 +806 +807 +808 +809
//  * This file is part of the uutils coreutils package.
 //  *
 //  * For the full copyright and license information, please view the LICENSE
@@ -1000,12 +1018,18 @@
     // numbers. We could split the options up into those groups to
     // reduce the coupling between this `table.rs` module and the main
     // `df.rs` module.
+    /// Whether to use the special rules for displaying the total row.
+    is_total_row: bool,
 }
 
 impl<'a> RowFormatter<'a> {
     /// Instantiate this struct.
-    pub(crate) fn new(row: &'a Row, options: &'a Options) -> Self {
-        Self { row, options }
+    pub(crate) fn new(row: &'a Row, options: &'a Options, is_total_row: bool) -> Self {
+        Self {
+            row,
+            options,
+            is_total_row,
+        }
     }
 
     /// Get a string giving the scaled version of the input number.
@@ -1047,13 +1071,25 @@
 
         for column in &self.options.columns {
             let string = match column {
-                Column::Source => self.row.fs_device.to_string(),
+                Column::Source => {
+                    if self.is_total_row {
+                        "total".to_string()
+                    } else {
+                        self.row.fs_device.to_string()
+                    }
+                }
                 Column::Size => self.scaled_bytes(self.row.bytes),
                 Column::Used => self.scaled_bytes(self.row.bytes_used),
                 Column::Avail => self.scaled_bytes(self.row.bytes_avail),
                 Column::Pcent => Self::percentage(self.row.bytes_usage),
 
-                Column::Target => self.row.fs_mount.to_string(),
+                Column::Target => {
+                    if self.is_total_row && !self.options.columns.contains(&Column::Source) {
+                        "total".to_string()
+                    } else {
+                        self.row.fs_mount.to_string()
+                    }
+                }
                 Column::Itotal => self.scaled_inodes(self.row.inodes),
                 Column::Iused => self.scaled_inodes(self.row.inodes_used),
                 Column::Iavail => self.scaled_inodes(self.row.inodes_free),
@@ -1167,7 +1203,7 @@
             // the output table.
             if options.show_all_fs || filesystem.usage.blocks > 0 {
                 let row = Row::from(filesystem);
-                let fmt = RowFormatter::new(&row, options);
+                let fmt = RowFormatter::new(&row, options, false);
                 let values = fmt.get_values();
                 total += row;
 
@@ -1182,7 +1218,7 @@
         }
 
         if options.show_total {
-            let total_row = RowFormatter::new(&total, options);
+            let total_row = RowFormatter::new(&total, options, true);
             rows.push(total_row.get_values());
         }
 
@@ -1421,7 +1457,7 @@
 
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(
             fmt.get_values(),
             vec!("my_device", "100", "25", "75", "25%", "my_mount")
@@ -1447,7 +1483,7 @@
 
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(
             fmt.get_values(),
             vec!("my_device", "my_type", "100", "25", "75", "25%", "my_mount")
@@ -1472,7 +1508,7 @@
 
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(
             fmt.get_values(),
             vec!("my_device", "10", "2", "8", "20%", "my_mount")
@@ -1491,7 +1527,7 @@
             inodes: 10,
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(fmt.get_values(), vec!("1", "10"));
     }
 
@@ -1514,7 +1550,7 @@
 
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(
             fmt.get_values(),
             vec!("my_device", "my_type", "4k", "1k", "3k", "25%", "my_mount")
@@ -1540,7 +1576,7 @@
 
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(
             fmt.get_values(),
             vec!("my_device", "my_type", "4K", "1K", "3K", "25%", "my_mount")
@@ -1557,7 +1593,7 @@
             bytes_usage: Some(0.251),
             ..Default::default()
         };
-        let fmt = RowFormatter::new(&row, &options);
+        let fmt = RowFormatter::new(&row, &options, false);
         assert_eq!(fmt.get_values(), vec!("26%"));
     }
 
@@ -1576,7 +1612,7 @@
                 bytes_avail,
                 ..Default::default()
             };
-            RowFormatter::new(&row, &options).get_values()
+            RowFormatter::new(&row, &options, false).get_values()
         }
 
         assert_eq!(get_formatted_values(100, 100, 0), vec!("1", "1", "0"));