forked from Morganamilo/paru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.rs
58 lines (47 loc) · 1.45 KB
/
remove.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::devel::{load_devel_info, save_devel_info};
use crate::print_error;
use crate::search::interactive_search_local;
use crate::util::pkg_base_or_name;
use crate::Config;
use crate::{exec, repo};
use std::collections::HashMap;
use anyhow::Result;
pub fn remove(config: &mut Config) -> Result<i32> {
if config.interactive {
interactive_search_local(config)?;
}
let mut devel_info = load_devel_info(config)?.unwrap_or_default();
let db = config.alpm.localdb();
let bases = config
.targets
.iter()
.filter_map(|pkg| db.pkg(pkg.as_str()).ok())
.map(pkg_base_or_name)
.collect::<Vec<_>>();
let mut db_map: HashMap<String, Vec<String>> = HashMap::new();
let (_, local_repos) = repo::repo_aur_dbs(config);
for pkg in &config.targets {
for db in &local_repos {
if let Ok(pkg) = db.pkg(pkg.as_str()) {
db_map
.entry(db.name().to_string())
.or_default()
.push(pkg.name().to_string());
}
}
}
let mut ret = exec::pacman(config, &config.args)?.code();
if ret != 0 {
return Ok(ret);
}
let (_, dbs) = repo::repo_aur_dbs(config);
for target in bases {
devel_info.info.remove(target);
}
drop(dbs);
if let Err(err) = save_devel_info(config, &devel_info) {
print_error(config.color.error, err);
ret = 1;
}
Ok(ret)
}