[gnome-boxes] os-database: avoid crash during wizard if loading failed
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] os-database: avoid crash during wizard if loading failed
- Date: Mon, 3 Sep 2012 16:09:44 +0000 (UTC)
commit 9748749aa5b4f06adf87db37d14f09d4f836cb07
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Mon Sep 3 15:59:33 2012 +0200
os-database: avoid crash during wizard if loading failed
We can quite easily avoid a crash during wizard if the db couldn't be
loaded, although this really shouldn't happen.
https://bugzilla.gnome.org/show_bug.cgi?id=683271
src/media-manager.vala | 3 ++-
src/os-database.vala | 12 ++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/media-manager.vala b/src/media-manager.vala
index de7505e..7159c3a 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -15,8 +15,9 @@ private class Boxes.MediaManager : Object {
public MediaManager () {
client = new GUdev.Client ({"block"});
+ os_db = new OSDatabase ();
try {
- os_db = new OSDatabase ();
+ os_db.load ();
} catch (GLib.Error error) {
critical ("Error fetching default OS database: %s", error.message);
}
diff --git a/src/os-database.vala b/src/os-database.vala
index 3fd6215..9885b43 100644
--- a/src/os-database.vala
+++ b/src/os-database.vala
@@ -16,7 +16,7 @@ private class Boxes.OSDatabase {
// dependent on the OS/guest.
private const int64 DEFAULT_STORAGE = 20 * (int64) GIBIBYTES;
- private Db db;
+ private Db? db;
private static Resources get_default_resources () {
var resources = new Resources ("whatever", "x86_64");
@@ -28,7 +28,7 @@ private class Boxes.OSDatabase {
return resources;
}
- public OSDatabase () throws GLib.Error {
+ public void load () throws GLib.Error {
var loader = new Loader ();
loader.process_default_path ();
loader.process_path (get_logos_db ()); // Load our custom database
@@ -38,12 +38,20 @@ private class Boxes.OSDatabase {
public async Os? guess_os_from_install_media (string media_path,
out Media os_media,
Cancellable? cancellable) throws GLib.Error {
+ os_media = null;
+
+ if (db == null)
+ return null;
+
var media = yield Media.create_from_location_async (media_path, Priority.DEFAULT, cancellable);
return db.guess_os_from_media (media, out os_media);
}
public Os get_os_by_id (string id) throws OSDatabaseError {
+ if (db == null)
+ throw new OSDatabaseError.UNKNOWN_OS_ID ("Unknown OS ID '%s'", id);
+
var os = db.get_os (id);
if (os == null)
throw new OSDatabaseError.UNKNOWN_OS_ID ("Unknown OS ID '%s'", id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]