Report the size used by the pile itself in the report
This commit is contained in:
parent
01c98cb415
commit
9e51c2428e
|
@ -13,6 +13,7 @@ use std::io::Read;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
use std::os::unix::fs::MetadataExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use yama::chunking::RecursiveUnchunker;
|
use yama::chunking::RecursiveUnchunker;
|
||||||
use yama::commands::{load_pile_descriptor, open_pile, retrieve_tree_node};
|
use yama::commands::{load_pile_descriptor, open_pile, retrieve_tree_node};
|
||||||
|
@ -371,7 +372,22 @@ fn format_size(chunks: u32, average_chunk_size: Option<f64>) -> String {
|
||||||
format!("{} c{}", chunks, est_size_suffix)
|
format!("{} c{}", chunks, est_size_suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn calculate_total_filesize_of_dir(dir: &Path) -> anyhow::Result<u64> {
|
||||||
|
let mut total = 0;
|
||||||
|
for file in std::fs::read_dir(dir)? {
|
||||||
|
let file = file?;
|
||||||
|
let metadata = file.metadata()?;
|
||||||
|
total += metadata.size();
|
||||||
|
if metadata.is_dir() {
|
||||||
|
total += calculate_total_filesize_of_dir(&file.path())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(total)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_filesystem_space(pile_path: &Path) -> anyhow::Result<()> {
|
pub fn print_filesystem_space(pile_path: &Path) -> anyhow::Result<()> {
|
||||||
|
let usage_for_pile = calculate_total_filesize_of_dir(&pile_path)?;
|
||||||
|
|
||||||
let path_c = CString::new(pile_path.as_os_str().as_bytes()).unwrap();
|
let path_c = CString::new(pile_path.as_os_str().as_bytes()).unwrap();
|
||||||
let stats = unsafe {
|
let stats = unsafe {
|
||||||
let mut stats: libc::statfs = mem::zeroed();
|
let mut stats: libc::statfs = mem::zeroed();
|
||||||
|
@ -409,6 +425,7 @@ pub fn print_filesystem_space(pile_path: &Path) -> anyhow::Result<()> {
|
||||||
Cell::new("Theoretical Size").fg(Color::Cyan),
|
Cell::new("Theoretical Size").fg(Color::Cyan),
|
||||||
Cell::new("Usable Size").fg(Color::Cyan),
|
Cell::new("Usable Size").fg(Color::Cyan),
|
||||||
Cell::new("Used").fg(Color::Cyan),
|
Cell::new("Used").fg(Color::Cyan),
|
||||||
|
Cell::new("Used for Pile").fg(Color::Cyan),
|
||||||
Cell::new("Available").fg(Color::Cyan),
|
Cell::new("Available").fg(Color::Cyan),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -428,6 +445,7 @@ pub fn print_filesystem_space(pile_path: &Path) -> anyhow::Result<()> {
|
||||||
.fg(Color::Blue),
|
.fg(Color::Blue),
|
||||||
Cell::new(format!("{:>9}", usable_bytes.file_size(&format).unwrap())).fg(Color::Blue),
|
Cell::new(format!("{:>9}", usable_bytes.file_size(&format).unwrap())).fg(Color::Blue),
|
||||||
Cell::new(format!("{:>9}", used_bytes.file_size(&format).unwrap())).fg(Color::Blue),
|
Cell::new(format!("{:>9}", used_bytes.file_size(&format).unwrap())).fg(Color::Blue),
|
||||||
|
Cell::new(format!("{:>9}", usage_for_pile.file_size(&format).unwrap())).fg(Color::Blue),
|
||||||
Cell::new(format!("{:>9}", avail_bytes.file_size(&format).unwrap()))
|
Cell::new(format!("{:>9}", avail_bytes.file_size(&format).unwrap()))
|
||||||
.fg(available_space_colour),
|
.fg(available_space_colour),
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in New Issue