Skip to main content

loadsmith_install/ops/
uninstall.rs

1use std::{fs, path::Path};
2
3use loadsmith_core::InstalledPackage;
4use tracing::{debug, trace};
5
6use crate::Result;
7
8pub fn uninstall(package: &InstalledPackage, profile: impl AsRef<Path>) -> Result<()> {
9    let profile = profile.as_ref();
10
11    for file in package.files() {
12        let target_path = profile.join(file.relative_path());
13
14        if target_path.exists() {
15            fs::remove_file(&target_path)?;
16            trace!(?file, "remove file");
17
18            loadsmith_util::remove_empty_parents(target_path)?;
19        } else {
20            debug!(?file, "file does not exist, skipping");
21        }
22    }
23
24    Ok(())
25}