From 1ea8ffaecb699aacfb4565f46a1542de1ea1e30d Mon Sep 17 00:00:00 2001 From: Bloxx12 Date: Sun, 4 May 2025 18:02:33 +0200 Subject: [PATCH] src/main.rs: add closure size flag --- Cargo.toml | 2 +- src/main.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d4efa4c..9b1a61b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "version-diff" +name = "nnpdt" version = "0.1.0" edition = "2024" diff --git a/src/main.rs b/src/main.rs index 7bfca71..88867d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,9 @@ use std::{ }; #[derive(Parser, Debug)] +#[command(name = "Nix not Python diff tool")] +#[command(version = "1.0")] +#[command(about = "Diff two different system closures", long_about = None)] #[command(version, about, long_about = None)] struct Args { path: std::path::PathBuf, @@ -17,6 +20,10 @@ struct Args { /// Print the whole store paths #[arg(short, long)] paths: bool, + + /// Print the closure size + #[arg(long, short)] + closure_size: bool, } // Only there to make the compiler shut up for now. @@ -116,6 +123,16 @@ fn main() { } } } + if args.closure_size { + let closure_size_pre = get_closure_size(&args.path) as i64; + let closure_size_post = get_closure_size(&args.path2) as i64; + + println!("{}", "Closure Size:".underline().bold()); + + println!("Before: {} MiB", closure_size_pre); + println!("After: {} MiB", closure_size_post); + println!("Difference: {} MiB", closure_size_post - closure_size_pre); + } } } @@ -159,3 +176,24 @@ fn check_nix_available() -> bool { nix_available.is_some() && nix_query_available.is_some() } + +fn get_closure_size(path: &std::path::Path) -> u64 { + let bytes = Command::new("nix") + .arg("path-info") + .arg("--closure-size") + .arg(path.join("sw")) + .output(); + + if let Ok(size) = bytes { + let res = str::from_utf8(&size.stdout); + if let Ok(res) = res { + let res = res.split_whitespace().last(); + if let Some(res) = res { + if let Ok(res) = res.parse::() { + return res / 1024 / 1024; + } + } + } + } + 0 +}