blob: 843115c8fe6b0f0e47e72df2bb9fd55a799b781f (
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
|
use std::path::PathBuf;
use tokio::fs;
use crate::AppImage;
#[derive(Debug, Default)]
pub struct SymlinkManager {}
impl SymlinkManager {
pub fn new() -> Self {
Self {}
}
pub async fn remove(&self, executable: &str) -> Result<(), Box<dyn std::error::Error>> {
let home = std::env::var("HOME")?;
let symlink_path = PathBuf::from(home).join(".local/bin").join(executable);
fs::remove_file(symlink_path).await?;
Ok(())
}
pub async fn create(&self, appimage: &AppImage) -> Result<(), Box<dyn std::error::Error>> {
let home = std::env::var("HOME")?;
let local_bin = PathBuf::from(home).join(".local/bin");
fs::create_dir_all(&local_bin).await?;
let symlink_path = local_bin.join(&appimage.executable);
#[cfg(unix)]
{
use tokio::fs;
if symlink_path.exists() {
fs::remove_file(&symlink_path).await?;
}
std::os::unix::fs::symlink(&appimage.file_path, &symlink_path)?;
}
Ok(())
}
}
|