X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/a9c6be4162bd15bd41ba3605127b56cb1eb32f32..edcd0e51b3e0a6d52a560f293b7e6a08999cfd0c:/src/command/publish_archive.rs diff --git a/src/command/publish_archive.rs b/src/command/publish_archive.rs index f5f114a..c727c16 100644 --- a/src/command/publish_archive.rs +++ b/src/command/publish_archive.rs @@ -1,5 +1,8 @@ -use std::io::Result; +use std::io::{Error, ErrorKind::Other, Result}; use crate::configuration::Configuration; +use std::process::{Command, Stdio}; + +const COMMAND: &str = "rsync"; pub struct PublishArchive; @@ -14,8 +17,27 @@ impl super::Command for PublishArchive { vec![] } - fn execute(&self, input: Option<&String>, _: &Configuration, _: &String) -> Result<()> { - println!("Publish Archive: {:?}!", input); + fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> { + + let input = input + .ok_or_else(|| Error::new(Other, "You must provide a location to publish the archive"))?; + + Command::new(COMMAND) + .arg("--version") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .map_err(|_| Error::new(Other, "Publishing requires rsync"))?; + + + Command::new(COMMAND) + .arg("-r") + .arg(format!("{}/", &configuration.archive_output_directory.display())) + .arg(input.as_str()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .map_err(|_| Error::new(Other, "Rsync failed to publish."))?; return Ok(()) }