From 52c2fc7bb4138634d8a629fc2563c0e00681c36e Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 31 Oct 2018 19:31:38 +0100 Subject: [PATCH] Optionally run rsync --- src/main.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index cd3f47b..33cdadb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,9 @@ use cursive::views::{Checkbox, Dialog, ListView, ProgressBar, TextView}; use cursive::Cursive; use failure::Error; use std::ffi::OsStr; +use std::os::unix::process::CommandExt; use std::path::PathBuf; +use std::process::Command; use std::sync::{Arc, Mutex}; use registry::Registry; @@ -145,10 +147,27 @@ fn save_albums(ui: &mut Cursive) { ui.pop_layer(); ui.add_layer( - Dialog::around(TextView::new("All albums have been saved!")).button("Ok", |ui| ui.quit()), + Dialog::around(TextView::new("All albums have been saved!\nSynchronise?")) + .button("Yes", |ui| sync_albums(ui)) + .button("No", |ui| ui.quit()), ); } +fn sync_albums(ui: &mut Cursive) { + let registry = REGISTRY.lock().unwrap(); + ui.quit(); + + Command::new("echo") + .arg("rsync") + .arg("-vaP") + .arg(&format!("--include-from={}.list.new", registry.device)) + .arg("--exclude=\"*\"") + .arg("--delete") + .arg(®istry.base_path) + .arg("target_path") + .exec(); +} + fn quit(ui: &mut Cursive) { ui.quit(); }