tangled
alpha
login
or
join now
tgirl.cloud
/
lix-diff
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
feat: remove unsafe rust
isabelroses.com
7 months ago
2a28a16e
5458a16e
+23
-12
2 changed files
expand all
collapse all
unified
split
src
main.rs
parser.rs
+7
-8
src/main.rs
reviewed
···
1
1
-
use std::{env, path::PathBuf};
1
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
36
+
let mut lix_exe = None;
36
37
if let Some(lix_bin) = lix_bin {
37
37
-
let current_path = env::var_os("PATH").unwrap();
38
38
-
let current_path = env::split_paths(¤t_path);
39
39
-
let new_path = std::iter::once(lix_bin).chain(current_path);
40
40
-
let new_path = env::join_paths(new_path).unwrap();
41
41
-
unsafe {
42
42
-
env::set_var("PATH", &new_path);
38
38
+
lix_exe = if lix_bin.is_dir() {
39
39
+
Some(lix_bin.join("nix"))
40
40
+
} else {
41
41
+
Some(lix_bin)
43
42
}
44
43
}
45
44
···
53
52
std::process::exit(1);
54
53
}
55
54
56
56
-
let packages: PackageListDiff = DiffRoot::new(&before, &after)?.into();
55
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
reviewed
···
1
1
use color_eyre::Result;
2
2
+
use serde::de::Deserializer;
2
3
use serde::Deserialize;
3
3
-
use serde::de::Deserializer;
4
4
-
use std::{borrow::Cow, collections::BTreeMap, path::Path, process::Command};
4
4
+
use std::{
5
5
+
borrow::Cow,
6
6
+
collections::BTreeMap,
7
7
+
path::{Path, PathBuf},
8
8
+
process::Command,
9
9
+
};
5
10
6
11
#[derive(Deserialize, Debug)]
7
12
pub struct DiffRoot {
···
41
46
}
42
47
43
48
impl DiffRoot {
44
44
-
pub fn new(before: &Path, after: &Path) -> Result<DiffRoot> {
45
45
-
let raw_diff = Command::new("nix")
49
49
+
pub fn new(lix_path: Option<PathBuf>, before: &Path, after: &Path) -> Result<DiffRoot> {
50
50
+
let lix_exe;
51
51
+
if let Some(lix_path) = lix_path {
52
52
+
lix_exe = lix_path;
53
53
+
} else {
54
54
+
lix_exe = "nix".into();
55
55
+
};
56
56
+
57
57
+
let raw_diff = Command::new(lix_exe)
46
58
.args(["store", "diff-closures", "--json"])
47
59
.args([before, after])
48
60
.output()?;