summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-08-13 12:06:43 +0100
committerdiogo464 <[email protected]>2025-08-13 12:06:43 +0100
commit1badf419bff94c475b3402c5d598112fa2d685f1 (patch)
treece7b1966d287340945e00c6356079cc4a3732533
parentfa28b81ffb4b695c057d38d86c9ccb526d2539c2 (diff)
cli: added drive-size subcommand
-rw-r--r--src/main.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 68b82ab..8f7723b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -768,6 +768,7 @@ enum Cmd {
768 Blob(BlobArgs), 768 Blob(BlobArgs),
769 Log(LogArgs), 769 Log(LogArgs),
770 Stat(StatArgs), 770 Stat(StatArgs),
771 DriveSize(DriveSizeArgs),
771} 772}
772 773
773#[derive(Debug, Args)] 774#[derive(Debug, Args)]
@@ -876,6 +877,12 @@ struct StatArgs {
876 path: DrivePath, 877 path: DrivePath,
877} 878}
878 879
880#[derive(Debug, Args)]
881struct DriveSizeArgs {
882 #[clap(flatten)]
883 common: CliCommon,
884}
885
879fn main() { 886fn main() {
880 let cli = Cli::parse(); 887 let cli = Cli::parse();
881 888
@@ -888,6 +895,7 @@ fn main() {
888 Cmd::Blob(args) => cmd_blob(args), 895 Cmd::Blob(args) => cmd_blob(args),
889 Cmd::Log(args) => cmd_log(args), 896 Cmd::Log(args) => cmd_log(args),
890 Cmd::Stat(args) => cmd_stat(args), 897 Cmd::Stat(args) => cmd_stat(args),
898 Cmd::DriveSize(args) => cmd_drive_size(args),
891 } 899 }
892} 900}
893 901
@@ -1153,6 +1161,14 @@ fn cmd_stat(args: StatArgs) {
1153 println!("{}", node.blob); 1161 println!("{}", node.blob);
1154} 1162}
1155 1163
1164fn cmd_drive_size(args: DriveSizeArgs) {
1165 let ops = common_read_log_file(&args.common);
1166 let mut fs = Fs::default();
1167 ops.iter().for_each(|op| apply(&mut fs, op).unwrap());
1168 compute_directory_sizes(&mut fs);
1169 println!("{}", fs.nodes[fs.root].size);
1170}
1171
1156fn collect_all_file_paths(root: &Path) -> Vec<PathBuf> { 1172fn collect_all_file_paths(root: &Path) -> Vec<PathBuf> {
1157 let mut queue = vec![root.to_path_buf()]; 1173 let mut queue = vec![root.to_path_buf()];
1158 let mut files = vec![]; 1174 let mut files = vec![];