From cfdb80af14336739e84294ab086607a18e838b55 Mon Sep 17 00:00:00 2001 From: Spencer Kohan Date: Sun, 19 Apr 2020 09:45:20 +0200 Subject: [PATCH] fixed route error --- src/cli.rs | 5 ++++- src/init.rs | 1 + src/main.rs | 15 ++++++++++----- src/remote.rs | 6 ++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 2f0ebc7..a91546a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,7 +6,9 @@ use serde::{Deserialize, Serialize}; #[derive(Clone)] pub enum SubCommand { #[structopt(name="init")] - Init(RemoteConfigRecord) + Init(RemoteConfigRecord), + #[structopt(name="clean")] + Clean, } #[derive(Debug)] @@ -37,3 +39,4 @@ pub struct RemoteConfigRecord { #[structopt(short = "u", long = "user")] pub user: String, } + diff --git a/src/init.rs b/src/init.rs index 3960ad5..371281e 100644 --- a/src/init.rs +++ b/src/init.rs @@ -12,6 +12,7 @@ pub enum InitError { fn create_dirsync_dirs() -> Result<(), std::io::Error> { fs::create_dir_all("./.dirsync/actions/onSyncDidFinish")?; + fs::create_dir_all("./.dirsync/actions/onSessionDidStart")?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 15571ac..bf2dec1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,12 +20,12 @@ fn rsync(config: &config::SessionConfig) { use std::process::Command; // we sync actions explicitly here, since they might be ignored otherwise - let dirsync_dir_local = &format!("{}/.dirsync/actions", &config.local_root); + let dirsync_dir_local = &format!("{}/.dirsync", &config.local_root); let dirsync_dir_remote = &format!("{}", &config.destination()); let output = &Command::new("rsync") .arg("-v") // verbose output - .arg("-r") + .arg("-ar") .arg(dirsync_dir_local) .arg(dirsync_dir_remote) .output() @@ -41,7 +41,7 @@ fn rsync(config: &config::SessionConfig) { let output = &Command::new("rsync") .arg("-v") // verbose output - .arg("-r") + .arg("-ar") .arg(format!("--exclude-from={}", config.exclude_path().to_str().unwrap())) .arg("--exclude-from=.gitignore") .arg(&config.local_root) @@ -59,7 +59,7 @@ fn rsync(config: &config::SessionConfig) { let output = &Command::new("rsync") .arg("-v") // verbose output - .arg("-r") + .arg("-ar") .arg(format!("--exclude-from={}", config.exclude_path().to_str().unwrap())) .arg(&config.local_root) .arg(&config.destination()) @@ -92,7 +92,7 @@ fn start_main_loop(config: &SessionConfig) { rsync(&config); let mut remote = remote::Remote::connect(config); - remote.execute_if_exists("onSyncDidFinish"); + remote.execute_if_exists("onSessionDidStart"); // Create a channel to receive the events. let (tx, rx) = channel(); @@ -124,6 +124,11 @@ fn main() { match opts.subcommand { Some(SubCommand::Init(remote_config)) => init::init_dirsync_dir(remote_config).unwrap(), + Some(SubCommand::Clean) => { + let config = SessionConfig::get(opts); + let mut remote = remote::Remote::connect(&config); + remote.remove_dir(config.remote.root.as_str()); + }, _ => { let config = SessionConfig::get(opts); start_main_loop(&config); diff --git a/src/remote.rs b/src/remote.rs index 5a17f8b..2cd929e 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -100,4 +100,10 @@ impl Remote { self.exec_stream(&command2); } + pub fn remove_dir(&mut self, path: &str) { + let command = &format!("rm -rf {}", path); + let s = self.exec(&command); + print!("clean result: {}\n", s); + } + } \ No newline at end of file