diff options
| author | Naz <ndpm13@ch-naseem.com> | 2025-07-29 13:46:43 +0100 |
|---|---|---|
| committer | Naz <ndpm13@ch-naseem.com> | 2025-07-29 13:46:43 +0100 |
| commit | bd8adb9f0193f1482ca866b06cf133ff68fd9a8e (patch) | |
| tree | 8d29230c9821e0512c207e2415e682a997090d2e /src/symlink.rs | |
| parent | f419a08d2861d76dce3d2a8206d6f1eb24bf1f2e (diff) | |
🔧refactor: remove types.rs
Diffstat (limited to 'src/symlink.rs')
| -rw-r--r-- | src/symlink.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/symlink.rs b/src/symlink.rs new file mode 100644 index 0000000..3883172 --- /dev/null +++ b/src/symlink.rs @@ -0,0 +1,34 @@ +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 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(()) + } +} |
