mirror of
https://github.com/RGBCube/dix
synced 2025-07-28 12:17:45 +00:00
src/main.rs: cleanup, add get_dependencies
This commit is contained in:
parent
93c8f55d30
commit
7ff637450d
1 changed files with 27 additions and 11 deletions
38
src/main.rs
38
src/main.rs
|
@ -70,8 +70,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare the package names of both versions
|
// Compare the package names of both versions
|
||||||
let pre_keys: HashSet<&str> = pre.keys().map(|k| *k).collect();
|
let pre_keys: HashSet<&str> = pre.keys().copied().collect();
|
||||||
let post_keys: HashSet<&str> = post.keys().map(|k| *k).collect();
|
let post_keys: HashSet<&str> = post.keys().copied().collect();
|
||||||
// get the intersection of the package names for version changes
|
// get the intersection of the package names for version changes
|
||||||
let maybe_changed: HashSet<_> = pre_keys.intersection(&post_keys).collect();
|
let maybe_changed: HashSet<_> = pre_keys.intersection(&post_keys).collect();
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ fn main() {
|
||||||
for p in added {
|
for p in added {
|
||||||
let versions = post.get(&p);
|
let versions = post.get(&p);
|
||||||
if let Some(ver) = versions {
|
if let Some(ver) = versions {
|
||||||
let version_str = ver.iter().map(|v| *v).collect::<Vec<_>>().join(" ").cyan();
|
let version_str = ver.iter().copied().collect::<Vec<_>>().join(" ").cyan();
|
||||||
println!(
|
println!(
|
||||||
"{} {} {} {}",
|
"{} {} {} {}",
|
||||||
"[A:]".green().bold(),
|
"[A:]".green().bold(),
|
||||||
|
@ -99,7 +99,7 @@ fn main() {
|
||||||
for p in removed {
|
for p in removed {
|
||||||
let version = pre.get(&p);
|
let version = pre.get(&p);
|
||||||
if let Some(ver) = version {
|
if let Some(ver) = version {
|
||||||
let version_str = ver.iter().map(|v| *v).collect::<Vec<_>>().join(" ").cyan();
|
let version_str = ver.iter().copied().collect::<Vec<_>>().join(" ").cyan();
|
||||||
println!(
|
println!(
|
||||||
"{} {} {} {}",
|
"{} {} {} {}",
|
||||||
"[R:]".red().bold(),
|
"[R:]".red().bold(),
|
||||||
|
@ -119,15 +119,10 @@ fn main() {
|
||||||
// can not fail since maybe_changed is the union of the keys of pre and post
|
// can not fail since maybe_changed is the union of the keys of pre and post
|
||||||
let ver_pre = pre.get(p).unwrap();
|
let ver_pre = pre.get(p).unwrap();
|
||||||
let ver_post = post.get(p).unwrap();
|
let ver_post = post.get(p).unwrap();
|
||||||
let version_str_pre = ver_pre
|
let version_str_pre = ver_pre.iter().copied().collect::<Vec<_>>().join(" ").cyan();
|
||||||
.iter()
|
|
||||||
.map(|v| *v)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(" ")
|
|
||||||
.cyan();
|
|
||||||
let version_str_post = ver_post
|
let version_str_post = ver_post
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| *v)
|
.copied()
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ")
|
.join(" ")
|
||||||
.cyan();
|
.cyan();
|
||||||
|
@ -158,6 +153,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gets the packages in a closure
|
||||||
fn get_packages(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
|
fn get_packages(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
|
||||||
// get the nix store paths using nix-store --query --references <path>
|
// get the nix store paths using nix-store --query --references <path>
|
||||||
let references = Command::new("nix-store")
|
let references = Command::new("nix-store")
|
||||||
|
@ -177,6 +173,26 @@ fn get_packages(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
|
||||||
Err(BlaErr::LolErr)
|
Err(BlaErr::LolErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gets the dependencies of the packages in a closure
|
||||||
|
fn get_dependencies(path: &std::path::Path) -> Result<Vec<String>, BlaErr> {
|
||||||
|
// get the nix store paths using nix-store --query --references <path>
|
||||||
|
let references = Command::new("nix-store")
|
||||||
|
.arg("--query")
|
||||||
|
.arg("--requisites")
|
||||||
|
.arg(path.join("sw"))
|
||||||
|
.output();
|
||||||
|
|
||||||
|
if let Ok(query) = references {
|
||||||
|
let list = str::from_utf8(&query.stdout);
|
||||||
|
|
||||||
|
if let Ok(list) = list {
|
||||||
|
let res: Vec<String> = list.lines().map(ToString::to_string).collect();
|
||||||
|
return Ok(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(BlaErr::LolErr)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_version<'a>(pack: impl Into<&'a str>) -> (&'a str, &'a str) {
|
fn get_version<'a>(pack: impl Into<&'a str>) -> (&'a str, &'a str) {
|
||||||
// funny regex to split a nix store path into its name and its version.
|
// funny regex to split a nix store path into its name and its version.
|
||||||
let re = Regex::new(r"^/nix/store/[a-z0-9]+-(.+?)-([0-9].*?)$").unwrap();
|
let re = Regex::new(r"^/nix/store/[a-z0-9]+-(.+?)-([0-9].*?)$").unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue