[gnome-boxes] app: Avoid adding duplicate sources
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] app: Avoid adding duplicate sources
- Date: Mon, 8 Apr 2013 15:54:30 +0000 (UTC)
commit 6b95a50c21747497a30cc68e4afc9859b0ab2b80
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Mar 29 04:55:17 2013 +0200
app: Avoid adding duplicate sources
Without this fix, we were adding the default 'QEMU Session' source
twice. It hasn't been a real problem so far but it will be after we
starting deleting stale box configs in the following patches.
We are now simply moving the add_collection_source out of
foreach_filename_from_dir's callback as we can't yield in there because
of bug#604827 and removing the explicit addition of 'QEMU Session'
source as it becomes redundant with this patch.
We were launching add_collection_source *async* for each source we found.
Since add_collection_source() checks if source is already added *before*
defering to mainloop, we could have a scenario like this:
1. source 'A' is found and add_collection source() defers to mainloop.
2. source 'B' (which is a duplicate of 'A') is found and
add_collection_source is launched for it too.
3. The add_collection source() from #1 has not yet added source 'A' so
the check for duplicate will fail and we'll still have a duplicated
source added.
https://bugzilla.gnome.org/show_bug.cgi?id=683489
src/app.vala | 27 +++++++++++++++------------
1 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index c612e56..872d8e8 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -365,6 +365,11 @@ private class Boxes.App: Boxes.UI {
if (!source.enabled)
return;
+ if (sources.get (source.name) != null) {
+ warning ("Attempt to add duplicate collection source '%s', ignoring..", source.name);
+ return; // Already added
+ }
+
switch (source.source_type) {
case "vnc":
case "spice":
@@ -404,23 +409,21 @@ private class Boxes.App: Boxes.UI {
}
}
- try {
- var source = new CollectionSource.with_file ("QEMU Session");
- yield add_collection_source (source);
- } catch (GLib.Error error) {
- warning (error.message);
- }
- if (default_connection == null) {
- printerr ("Missing or failing default libvirt connection\n");
- application.release (); // will end application
- }
-
var dir = File.new_for_path (get_user_pkgconfig_source ());
+ var new_sources = new GLib.List<CollectionSource> ();
yield foreach_filename_from_dir (dir, (filename) => {
var source = new CollectionSource.with_file (filename);
- add_collection_source.begin (source);
+ new_sources.append (source);
return false;
});
+
+ foreach (var source in new_sources)
+ yield add_collection_source (source);
+
+ if (default_connection == null) {
+ printerr ("Missing or failing default libvirt connection\n");
+ application.release (); // will end application
+ }
}
private void save_window_geometry () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]