[gnome-boxes] Remove a few warnings when deleting machine



commit e570f090c7cc5d7b4d890c54d88209ff59a60200
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Tue Feb 21 01:42:20 2012 +0100

    Remove a few warnings when deleting machine
    
    Do not attempt to undefine and remove storage in vm-creator if
    it's already done (by user for example)
    
    The patch also adds some debugging.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670539

 src/libvirt-machine.vala |    4 ++++
 src/vm-creator.vala      |   19 +++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 5cae081..b7fcc6b 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -104,6 +104,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                            GVir.Domain domain) throws GLib.Error {
         base (source, app, domain.get_name ());
 
+        debug ("new libvirt machine: " + name);
         this.config = new DisplayConfig (source, domain.get_uuid ());
         this.connection = connection;
         this.domain = domain;
@@ -228,6 +229,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     private uint stats_id;
     private void set_stats_enable (bool enable) {
         if (enable) {
+            debug ("enable statistics for " + name);
             if (stats_id != 0)
                 return;
 
@@ -236,6 +238,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                 return true;
             });
         } else {
+            debug ("disable statistics for " + name);
             if (stats_id != 0)
                 GLib.Source.remove (stats_id);
             stats_id = 0;
@@ -331,6 +334,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     }
 
     public override void delete (bool by_user = true) {
+        debug ("delete libvirt machine: " + name);
         base.delete (by_user);
 
         set_stats_enable (false);
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 1a3c8f9..d2674c1 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -7,6 +7,7 @@ private class Boxes.VMCreator {
     private App app;
     private Connection connection { get { return app.default_connection; } }
     private VMConfigurator configurator;
+    private ulong stopped_id;
 
     public VMCreator (App app) {
         configurator = new VMConfigurator ();
@@ -30,9 +31,10 @@ private class Boxes.VMCreator {
 
             var state = machine.domain.get_info ().state;
             if (state == DomainState.SHUTOFF || state == DomainState.CRASHED || state == DomainState.NONE)
-                on_domain_stopped (machine.domain);
-            else
-                machine.domain.stopped.connect (on_domain_stopped);
+                on_domain_stopped (machine);
+            else {
+                stopped_id = machine.domain.stopped.connect (() => { on_domain_stopped (machine); });
+            }
         } catch (GLib.Error error) {
             warning ("Failed to get information on domain '%s': %s", machine.domain.get_name (), error.message);
         }
@@ -73,7 +75,12 @@ private class Boxes.VMCreator {
         return domain;
     }
 
-    private void on_domain_stopped (Domain domain) {
+    private void on_domain_stopped (LibvirtMachine machine) {
+        var domain = machine.domain;
+
+        if (machine.deleted)
+            return;
+
         if (domain.get_saved ())
             // This means the domain was just saved and thefore this is not yet the time to take any post-install
             // steps for this domain.
@@ -83,7 +90,7 @@ private class Boxes.VMCreator {
 
         if (guest_installed_os (volume)) {
             post_install_setup (domain);
-            domain.stopped.disconnect (on_domain_stopped);
+            domain.disconnect (stopped_id);
         } else {
             try {
                 var config = domain.get_config (0);
@@ -92,7 +99,7 @@ private class Boxes.VMCreator {
                     return;
 
                 // No installation during live session, so lets delete the domain and its storage volume.
-                domain.stopped.disconnect (on_domain_stopped);
+                domain.disconnect (stopped_id);
                 domain.delete (0);
                 volume.delete (0);
             } catch (GLib.Error error) {



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