mirror of
https://github.com/RGBCube/dix
synced 2025-07-28 04:07:46 +00:00
src/main.rs: add closure size flag
This commit is contained in:
parent
2893509d42
commit
1ea8ffaecb
2 changed files with 39 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "version-diff"
|
||||
name = "nnpdt"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
|
|
38
src/main.rs
38
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::<u64>() {
|
||||
return res / 1024 / 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue