diff options
Diffstat (limited to 'src/remote')
| -rw-r--r-- | src/remote/git.rs | 14 | ||||
| -rw-r--r-- | src/remote/mod.rs | 4 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/remote/git.rs b/src/remote/git.rs index a4c1c28..66c5a89 100644 --- a/src/remote/git.rs +++ b/src/remote/git.rs @@ -1,6 +1,6 @@ -use std::io::Result; +use std::io::{Error, ErrorKind::Other, Result}; use std::path::PathBuf; -use std::process::Command; +use std::process::{Command, Stdio}; use std::time::{SystemTime, UNIX_EPOCH}; pub struct Git; @@ -19,7 +19,7 @@ impl super::Remote for Git { fn sync_up(&self, remote: &str, directory: &PathBuf) -> Result<()> { let timestamp = SystemTime::now().duration_since(UNIX_EPOCH) - .expect("Invalid time") + .map_err(|_| Error::new(Other, "Invalid time"))? .as_millis(); let commands = vec![ @@ -33,8 +33,10 @@ impl super::Remote for Git { Command::new("sh") .arg("-c") .arg(&command) + .stdout(Stdio::null()) + .stderr(Stdio::null()) .status() - .expect("Failed while performing sync up with git"); + .map_err(|_| Error::new(Other, "Failed while performing sync up with git"))?; } Ok(()) @@ -52,8 +54,10 @@ impl super::Remote for Git { Command::new("sh") .arg("-c") .arg(&command) + .stdout(Stdio::null()) + .stderr(Stdio::null()) .status() - .expect("Failed while performing sync down with git"); + .map_err(|_| Error::new(Other, "Failed while performing sync down with git"))?; } Ok(()) } diff --git a/src/remote/mod.rs b/src/remote/mod.rs index de90ef5..19514af 100644 --- a/src/remote/mod.rs +++ b/src/remote/mod.rs @@ -27,7 +27,7 @@ pub fn remove(remote_config: &PathBuf) -> Result<()> { pub fn sync_up(data_directory: &PathBuf, remote_config: &PathBuf) -> Result<()> { let remote_address = read_remote(remote_config) - .expect("No remote is configured"); + .ok_or_else(|| Error::new(Other, "No remote is configured"))?; create_dir_all(data_directory)?; let remotes = available_remotes(); for remote in remotes { @@ -40,7 +40,7 @@ pub fn sync_up(data_directory: &PathBuf, remote_config: &PathBuf) -> Result<()> pub fn sync_down(data_directory: &PathBuf, remote_config: &PathBuf) -> Result<()> { let remote_address = read_remote(remote_config) - .expect("No remote is configured"); + .ok_or_else(|| Error::new(Other, "No remote is configured"))?; create_dir_all(data_directory)?; let remotes = available_remotes(); for remote in remotes { |