this repo has no description

feat: remove unsafe rust

+23 -12
+7 -8
src/main.rs
··· 1 - use std::{env, path::PathBuf}; 1 + use std::path::PathBuf; 2 2 3 3 use clap::Parser; 4 4 use color_eyre::Result; ··· 33 33 let after = args.after; 34 34 let lix_bin = args.lix_bin; 35 35 36 + let mut lix_exe = None; 36 37 if let Some(lix_bin) = lix_bin { 37 - let current_path = env::var_os("PATH").unwrap(); 38 - let current_path = env::split_paths(&current_path); 39 - let new_path = std::iter::once(lix_bin).chain(current_path); 40 - let new_path = env::join_paths(new_path).unwrap(); 41 - unsafe { 42 - env::set_var("PATH", &new_path); 38 + lix_exe = if lix_bin.is_dir() { 39 + Some(lix_bin.join("nix")) 40 + } else { 41 + Some(lix_bin) 43 42 } 44 43 } 45 44 ··· 53 52 std::process::exit(1); 54 53 } 55 54 56 - let packages: PackageListDiff = DiffRoot::new(&before, &after)?.into(); 55 + let packages: PackageListDiff = DiffRoot::new(lix_exe, &before, &after)?.into(); 57 56 58 57 let arrow_style = Style::new().bold().fg(Color::LightGray); 59 58
+16 -4
src/parser.rs
··· 1 1 use color_eyre::Result; 2 + use serde::de::Deserializer; 2 3 use serde::Deserialize; 3 - use serde::de::Deserializer; 4 - use std::{borrow::Cow, collections::BTreeMap, path::Path, process::Command}; 4 + use std::{ 5 + borrow::Cow, 6 + collections::BTreeMap, 7 + path::{Path, PathBuf}, 8 + process::Command, 9 + }; 5 10 6 11 #[derive(Deserialize, Debug)] 7 12 pub struct DiffRoot { ··· 41 46 } 42 47 43 48 impl DiffRoot { 44 - pub fn new(before: &Path, after: &Path) -> Result<DiffRoot> { 45 - let raw_diff = Command::new("nix") 49 + pub fn new(lix_path: Option<PathBuf>, before: &Path, after: &Path) -> Result<DiffRoot> { 50 + let lix_exe; 51 + if let Some(lix_path) = lix_path { 52 + lix_exe = lix_path; 53 + } else { 54 + lix_exe = "nix".into(); 55 + }; 56 + 57 + let raw_diff = Command::new(lix_exe) 46 58 .args(["store", "diff-closures", "--json"]) 47 59 .args([before, after]) 48 60 .output()?;