[gnome-boxes] libvirt-sys-importer: import_domain() handle errors



commit dd9256d64f4a2f26db3a7b806dcfd4e2066bdd0d
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Jul 21 16:49:29 2015 +0100

    libvirt-sys-importer: import_domain() handle errors
    
    import_domain() should be handling it's own errors anyway but this is
    also needed cause vala doesn't seem to copy/ref array of objects for
    closure and hence we have a potential crash at our hand if the calling
    function, import() handles the errors from import_domain()
    asynchronously, where it accesses the domain config array.

 src/libvirt-system-importer.vala |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/src/libvirt-system-importer.vala b/src/libvirt-system-importer.vala
index e1259b6..43c4ef4 100644
--- a/src/libvirt-system-importer.vala
+++ b/src/libvirt-system-importer.vala
@@ -73,13 +73,7 @@ private class Boxes.LibvirtSystemImporter: GLib.Object {
         }
 
         for (var i = 0; i < configs.length; i++)
-            import_domain.begin (configs[i], disk_paths[i], null, (obj, result) => {
-                try {
-                    import_domain.end (result);
-                } catch (GLib.Error error) {
-                    warning ("Failed to import '%s': %s", configs[i].name, error.message);
-                }
-            });
+            import_domain.begin (configs[i], disk_paths[i], null);
     }
 
     private void get_domain_info (Domain domain,
@@ -93,13 +87,17 @@ private class Boxes.LibvirtSystemImporter: GLib.Object {
 
     private async void import_domain (GVirConfig.Domain config,
                                       string            disk_path,
-                                      Cancellable?      cancellable = null) throws GLib.Error {
+                                      Cancellable?      cancellable = null) {
         debug ("Importing '%s' from system libvirt..", config.name);
 
-        var media = new LibvirtSystemMedia (disk_path, config);
-        var vm_importer = media.get_vm_creator ();
-        var machine = yield vm_importer.create_vm (cancellable);
-        vm_importer.launch_vm (machine);
+        try {
+            var media = new LibvirtSystemMedia (disk_path, config);
+            var vm_importer = media.get_vm_creator ();
+            var machine = yield vm_importer.create_vm (cancellable);
+            vm_importer.launch_vm (machine);
+        } catch (GLib.Error error) {
+            warning ("Failed to import '%s': %s", config.name, error.message);
+        }
     }
 
     private string get_disk_path (GVirConfig.Domain config) throws 
LibvirtSystemImporterError.NO_SUITABLE_DISK {


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