common: Include the recordings' size in the listing.
authorTilman Sauerbeck <tilman@code-monkey.de>
Mon, 13 Jan 2020 07:27:02 +0000 (08:27 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Mon, 13 Jan 2020 07:27:02 +0000 (08:27 +0100)
The size is only approximate (i.e. multiples of sectors used).

src/common/logger.rs
test/logger_test.rs

index 2ca2e22980f48b7867abddae91b2e09e1506c7d2..1c982afa96163cb68714d491c10a3f0d3217593f 100644 (file)
@@ -554,6 +554,17 @@ impl<'a> Logger<'a> {
                 continue;
             }
 
+            let mut num_data_sectors = 0;
+
+            for d in 1..NUM_SECTORS {
+                let wrapped_index = ((index + d) & (NUM_SECTORS - 1)) as usize;
+                let other_sector_header = &self.sector_header[wrapped_index];
+
+                if other_sector_header.belongs_to(sector_header.recording_id) {
+                    num_data_sectors += 1;
+                }
+            }
+
             let mut date_time_s = [b' '; 19];
 
             if let Some(tm) = Time::from_unix_time(sector_header.start_time) {
@@ -561,6 +572,13 @@ impl<'a> Logger<'a> {
                 tm.fmt_time(&mut date_time_s[11..]);
             }
 
+            let recording_size = (num_data_sectors + 1) * (SECTOR_SIZE >> 10);
+
+            let mut recording_size_s = [b'0'; 9];
+            let recording_size_s_len = fmt_u32_pad(&mut recording_size_s,
+                                                   recording_size as u32,
+                                                   8, b' ');
+
             let mut recording_id_s = [b'0'; 9];
             let recording_id_s_len =
                 fmt_u32_pad(&mut recording_id_s,
@@ -568,7 +586,8 @@ impl<'a> Logger<'a> {
                             8, b' ');
 
             tx_buf.write(&date_time_s);
-            tx_buf.write(b"       ");
+            tx_buf.write(&recording_size_s[0..recording_size_s_len]);
+            tx_buf.write(b"K");
             tx_buf.write(&recording_id_s[0..recording_id_s_len]);
             tx_buf.write(b"\n");
 
index b11005568bdb95dacfc6327d870ac67a79aeaaa4..cf4984a3d4dd562ec7d642311cc039061d993e60 100644 (file)
@@ -425,7 +425,7 @@ fn list_recordings1() {
     let num_bytes_read = file.read(&mut listing_raw).unwrap();
 
     let expected_bytes = b"\
-2020-01-07 19:27:30              1\n";
+2020-01-07 19:27:30       4K       1\n";
 
     assert_eq!(String::from_utf8(expected_bytes.to_vec()).unwrap(),
                String::from_utf8(listing_raw[0..num_bytes_read].to_vec()).unwrap());
@@ -477,7 +477,7 @@ fn list_recording1_multi_sector() {
     let num_bytes_read = file.read(&mut listing_raw).unwrap();
 
     let expected_bytes = b"\
-2020-01-09 12:11:33              1\n";
+2020-01-09 12:11:33       8K       1\n";
 
     assert_eq!(String::from_utf8(expected_bytes.to_vec()).unwrap(),
                String::from_utf8(listing_raw[0..num_bytes_read].to_vec()).unwrap());