diff options
| author | Naz <ndpm13@ch-naseem.com> | 2025-07-30 07:11:24 +0100 |
|---|---|---|
| committer | Naz <ndpm13@ch-naseem.com> | 2025-07-30 07:11:24 +0100 |
| commit | df40ab0fd7d9641297833dc7e0691522c25e2bc9 (patch) | |
| tree | b185168ceedb4f71b255e7e61a365566da41538d /src/symlink.rs | |
| parent | d3c84b04d7a46735dd19a2dae9448e811a609291 (diff) | |
| parent | 11a86042e73bb0eecad61ac6e636dd98563167f5 (diff) | |
Merge pull request '🔧refactor: separate download logic from AppImage struct' (#11) from feat/issue-7 into main
Reviewed-on: https://git.ch-naseem.com/ndpm13/zap-rs/pulls/11
Diffstat (limited to 'src/symlink.rs')
| -rw-r--r-- | src/symlink.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/symlink.rs b/src/symlink.rs new file mode 100644 index 0000000..843115c --- /dev/null +++ b/src/symlink.rs @@ -0,0 +1,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(()) + } +} |
