[gnome-boxes] collection-source: Add purge_stale_box_configs() method



commit c9d6e2e48ec3b671020d21067c683916e337f4cf
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Mar 28 20:36:54 2013 +0200

    collection-source: Add purge_stale_box_configs() method
    
    Add a method to purge all stale box configs under the collection source.
    A box config can become stale if box (e.g libvirt domain) is removed
    using a UI other than Boxes (e.g virt-manager, virsh etc).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683489

 src/collection-source.vala |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/src/collection-source.vala b/src/collection-source.vala
index 5a79738..fbdb338 100644
--- a/src/collection-source.vala
+++ b/src/collection-source.vala
@@ -126,4 +126,31 @@ public class Boxes.CollectionSource: GLib.Object, Boxes.IConfig {
         FileUtils.unlink (get_user_pkgconfig_source (filename));
         has_file = false;
     }
+
+    public void purge_stale_box_configs (GLib.List<BoxConfig> used_configs) {
+        foreach (var group in keyfile.get_groups ()) {
+            if (group == "source")
+                continue;
+
+            var stale = true;
+            foreach (var config in used_configs) {
+                if (config.group == group) {
+                    stale = false;
+
+                    break;
+                }
+            }
+
+            if (stale) {
+                try {
+                    keyfile.remove_group (group);
+                    debug ("Removed stale box config '%s'", group);
+                } catch (GLib.Error e) {
+                    debug ("Error removing stale stale box config '%s': %s", group, e.message);
+                }
+            }
+        }
+
+        save ();
+    }
 }


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