[gnome-boxes/gnome-3-12] app: Create qemu session source file if its empty



commit 59ea141ffc493ec026e79d79593f73dfd84909c3
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue May 13 15:34:27 2014 +0100

    app: Create qemu session source file if its empty
    
    Instead of only creating qemu session source file if it doesn't exist,
    also check if its empty and create it if thats the case.
    
    This fixes a crash that can happen if Boxes crashed on a previous run
    between the time the file is created and copied.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730022

 src/app.vala |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 4ac2474..fdf44db 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -366,12 +366,24 @@ private class Boxes.App: Gtk.Application, Boxes.UI {
     }
 
     private async void setup_sources () {
+        var path = get_user_pkgconfig_source ("QEMU Session");
+        var create_session_source = true;
+        try {
+            var file = File.new_for_path (path);
+            var info = yield file.query_info_async (FileAttribute.STANDARD_SIZE,
+                                                    FileQueryInfoFlags.NONE,
+                                                    Priority.DEFAULT,
+                                                    null);
+            create_session_source = (info.get_attribute_uint64 (FileAttribute.STANDARD_SIZE) <= 0);
+        } catch (GLib.Error error) {
+            debug ("Failed to query '%s': %s. Assuming it doesn't exist.", path, error.message);
+        }
 
-        if (!FileUtils.test (get_user_pkgconfig_source ("QEMU Session"), FileTest.IS_REGULAR)) {
+        if (create_session_source) {
             var src = File.new_for_path (get_pkgdata_source ("QEMU_Session"));
-            var dst = File.new_for_path (get_user_pkgconfig_source ("QEMU Session"));
+            var dst = File.new_for_path (path);
             try {
-                yield src.copy_async (dst, FileCopyFlags.NONE);
+                yield src.copy_async (dst, FileCopyFlags.OVERWRITE);
             } catch (GLib.Error error) {
                 critical ("Can't setup default sources: %s", error.message);
             }


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