1use std::path::PathBuf;
2use tokio::fs;
3
4use crate::{AppImage, Result};
5
6#[derive(Debug, Default)]
7pub struct SymlinkManager {}
8
9impl SymlinkManager {
10 pub fn new() -> Self {
11 Self {}
12 }
13 pub async fn remove(&self, executable: &str) -> Result<()> {
14 let home = std::env::var("HOME")?;
15 let symlink_path = PathBuf::from(home).join(".local/bin").join(executable);
16
17 fs::remove_file(symlink_path).await?;
18
19 Ok(())
20 }
21 pub async fn create(&self, appimage: &AppImage) -> Result<()> {
22 let home = std::env::var("HOME")?;
23 let local_bin = PathBuf::from(home).join(".local/bin");
24
25 fs::create_dir_all(&local_bin).await?;
26
27 let symlink_path = local_bin.join(&appimage.executable);
28
29 #[cfg(unix)]
30 {
31 use tokio::fs;
32
33 if symlink_path.exists() {
34 fs::remove_file(&symlink_path).await?;
35 }
36
37 std::os::unix::fs::symlink(&appimage.file_path, &symlink_path)?;
38 }
39
40 Ok(())
41 }
42}