-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a2bba0
commit f73501c
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::installer::Installer; | ||
|
||
use anyhow::{anyhow, Context, Error, Result}; | ||
|
||
pub struct Symlink { | ||
name: String, | ||
version: String, | ||
path: std::path::PathBuf, | ||
} | ||
|
||
impl Symlink { | ||
pub fn new( | ||
name: &String, | ||
version: &str, | ||
app_config: &serde_yaml::Mapping, | ||
) -> Result<Self, Error> { | ||
let path = match app_config.get("path") { | ||
Some(serde_yaml::Value::String(path)) => std::path::Path::new(path), | ||
_ => { | ||
return Err(anyhow!("Expected a string path in config for {}", name)); | ||
} | ||
}; | ||
|
||
Ok(Symlink { | ||
name: name.clone(), | ||
version: version.to_string(), | ||
path: path.to_owned() | ||
}) | ||
} | ||
} | ||
|
||
impl Installer for Symlink { | ||
fn install(&self, to_dir: &std::path::Path) -> Result<()> { | ||
eprintln!("Running {}", self.describe()); | ||
std::fs::create_dir_all(to_dir)?; | ||
|
||
if !self.path.exists() { | ||
return Err(anyhow!("Destination symlink {} doesn't exist", self.path.display())) | ||
} | ||
|
||
let file = to_dir.join(&self.name); | ||
std::os::unix::fs::symlink(&self.path, &file).context(anyhow!("Unable to symlink {} to {}", self.path.display(), file.display())) | ||
} | ||
|
||
fn describe(&self) -> String { | ||
format!("symlink installer for {} v.{}", self.name, self.version) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters