Terminate rsync when user closes main window

This commit is contained in:
Tony George 2013-12-27 22:31:48 +05:30
parent 49de846a01
commit 245472985e
3 changed files with 32 additions and 3 deletions

View File

@ -2437,6 +2437,30 @@ public class Main : GLib.Object{
//Gtk.main_quit ();
}
public bool is_rsync_running(){
string cmd = "rsync -ai --delete --numeric-ids --relative --delete-excluded";
string txt = execute_command_sync_get_output ("ps w -C rsync");
foreach(string line in txt.split("\n")){
if (line.index_of(cmd) != -1){
return true;
}
}
return false;
}
public void kill_rsync(){
string cmd = "rsync -ai --delete --numeric-ids --relative --delete-excluded";
string txt = execute_command_sync_get_output ("ps w -C rsync");
string pid = "";
foreach(string line in txt.split("\n")){
if (line.index_of(cmd) != -1){
pid = line.strip().split(" ")[0];
Posix.kill ((Pid) int.parse(pid), 15);
log_msg(_("Terminating rsync process") + ": [PID=" + pid + "] ");
}
}
}
}
public class TimeShiftBackup : GLib.Object{

View File

@ -475,7 +475,12 @@ class MainWindow : Gtk.Window{
private bool on_delete_event(Gdk.EventAny event){
this.delete_event.disconnect(on_delete_event); //disconnect this handler
if (App.is_rsync_running()){
log_error (_("Main window closed by user"));
App.kill_rsync();
}
if (!App.is_scheduled){
return false; //close window
}

View File

@ -62,7 +62,7 @@ namespace TeeJee.Logging{
}
if (LOG_TIMESTAMP){
msg += "[" + timestamp() + "] ";
msg += timestamp() + " ";
}
msg += message;
@ -95,7 +95,7 @@ namespace TeeJee.Logging{
}
if (LOG_TIMESTAMP){
msg += "[" + timestamp() + "] ";
msg += timestamp() + " ";
}
string prefix = (is_warning) ? _("Warning") : _("Error");