[gnome-boxes/create-vms-properly-on-second-trial] assistant, review-page: Do the cancellation of VM creation properly



commit b55123c13a6f2f3fe2011f2a30b07cc98fe8cbf0
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Jun 4 15:43:47 2020 +0200

    assistant, review-page: Do the cancellation of VM creation properly
    
    Boxes was failing at creating a VM when the user gave up on creating
    a certain VM and instead decides to go back and create a new one
    from another image/ISO.
    
    The reason was that we were calling the cancellable.cancel
    ourselves and never reseting the state of the GLib.Cancellable
    object for the following VM creation attempt.
    
    The proper handle of a GLib.Cancellable object is to drop the
    reference right after cancelling and instantiating a brand new
    GLib.Cancellable object for other operation. In other words, one
    Cancellable per operation. I learned that the hard way. :)

 src/assistant/review-page.vala | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/src/assistant/review-page.vala b/src/assistant/review-page.vala
index 5768b835..43e9bd42 100644
--- a/src/assistant/review-page.vala
+++ b/src/assistant/review-page.vala
@@ -14,7 +14,7 @@
     private Stack customization_stack;
     private GLib.List<Boxes.Property> resource_properties;
 
-    private Cancellable cancellable = new GLib.Cancellable ();
+    private Cancellable? cancellable;
 
     [GtkCallback]
     private void on_customize_button_toggled () {
@@ -23,7 +23,7 @@ private void on_customize_button_toggled () {
     }
 
     public async void setup (VMCreator vm_creator) {
-        resource_properties = new GLib.List<Boxes.Property> ();
+        cancellable = new GLib.Cancellable ();
 
         try {
             artifact = yield vm_creator.create_vm (cancellable);
@@ -73,10 +73,14 @@ public async void populate (LibvirtMachine machine) {
     }
 
     private void populate_customization_grid (LibvirtMachine machine) {
+        resource_properties = new GLib.List<Boxes.Property> ();
         machine.properties.get_resources_properties (ref resource_properties);
 
         return_if_fail (resource_properties.length () > 0);
 
+        foreach (var child in customization_grid.get_children ())
+            customization_grid.remove (child);
+
         var current_row = 0;
         foreach (var property in resource_properties) {
             if (property.widget == null || property.extra_widget == null) {
@@ -97,7 +101,10 @@ private void populate_customization_grid (LibvirtMachine machine) {
     }
 
     public override void cleanup () {
-        cancellable.cancel ();
+        if (cancellable != null) {
+            cancellable.cancel ();
+            cancellable = null;
+        }
 
         summary.clear ();
         nokvm_infobar.hide ();
@@ -123,6 +130,7 @@ public override async void next () {
         foreach (var property in resource_properties) {
             property.flush ();
         }
+        resource_properties = null;
 
         done (artifact);
 


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