[gnome-boxes] libvirt-machine: Delay starting if being saved



commit cc0832efadd8afcbe461cced38e2d6e526866a5a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Nov 10 19:27:40 2014 +0000

    libvirt-machine: Delay starting if being saved
    
    Connecting to a machine that is currently being saved results in an
    error so lets wait for saving to finish completely before we launch the
    machine.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694931

 src/libvirt-machine.vala |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 22532b6..742ed02 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -40,6 +40,14 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     public override async void connect_display (Machine.ConnectFlags flags) throws GLib.Error {
         connecting_cancellable.reset ();
 
+        yield wait_for_save ();
+
+        if (connecting_cancellable.is_cancelled ()) {
+            connecting_cancellable.reset ();
+
+            return;
+        }
+
         yield start (flags, connecting_cancellable);
         if (connecting_cancellable.is_cancelled ()) {
             connecting_cancellable.reset ();
@@ -618,4 +626,30 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
 
         try_shutdown ();
     }
+
+    private async void wait_for_save () {
+        if (!saving)
+            return;
+
+        var state_notify_id = notify["state"].connect (() => {
+            if (state == MachineState.SAVED)
+                wait_for_save.callback ();
+        });
+        var cancelled_id = connecting_cancellable.cancelled.connect (() => {
+            Idle.add (() => {
+                // This callback is synchronous and calling it directly from cancelled callback will mean
+                // disconnecting from this signal and resetting cancellable from right here and that seems 
to hang
+                // the application.
+                wait_for_save.callback ();
+
+                return false;
+            });
+        });
+
+        debug ("%s is being saved, delaying starting untill its saved", name);
+        yield;
+
+        disconnect (state_notify_id);
+        connecting_cancellable.disconnect (cancelled_id);
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]