blob: abe23e32e6d8a84a1dd95e26b831920585e39cf1 (
plain)
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
|
use std::{
fs::{DirEntry, Metadata},
path::{Path, PathBuf},
};
use super::prelude::*;
/// Unlinks files/directories.
///
/// This will recursively remove links. If a path is a directory then it will remove all links
/// recursively.
/// The links are not uninstall by default, see the --uninstall parameter.
#[derive(Parser)]
pub struct Opts {
/// Specify the install base if the links are also to be uninstalled.
#[clap(long)]
uninstall: Option<PathBuf>,
/// The paths to unlink.
#[clap(required = true, min_values = 1)]
paths: Vec<PathBuf>,
}
pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
let mut depot = utils::read_depot(&config.archive_path)?;
for link_id in utils::collect_link_ids_by_base_paths(&depot, &opts.paths) {
let link = depot.get_link(link_id).unwrap();
log::info!(
"Unlinking(uninstall = {}) : {}",
opts.uninstall.is_some(),
link
);
if let Some(ref install_base) = opts.uninstall {
depot.uninstall_link(link, &install_base)?;
}
depot.remove_link(link_id);
}
utils::write_depot(&depot)?;
Ok(())
}
|