[gnome-boxes] app,util: Move config files from .cache on startup



commit 0b9353f41e5f4a6b1dcaf80ad916b5e938d93f7b
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Mar 15 14:28:55 2016 +0000

    app,util: Move config files from .cache on startup
    
    We just fixed the regression of Boxes keeping configuration files under
    ~/.cache rather than ~/.config but since this regression has existed for a
    long time now, many users would have their configurations under ~/.cache
    now so we need to ensure the configuration gets moved under ~/.config.

 src/app.vala      |    2 ++
 src/util-app.vala |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 39c2c6f..784544a 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -385,6 +385,8 @@ private class Boxes.App: Gtk.Application {
     }
 
     private async void activate_async () {
+        yield move_configs_from_cache ();
+
         yield setup_default_source ();
 
         is_ready = true;
diff --git a/src/util-app.vala b/src/util-app.vala
index ff530bb..0aeee2f 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -526,6 +526,43 @@ namespace Boxes {
         return tokens[1];
     }
 
+    // Move all configurations from ~/.cache to ~/.config
+    public async void move_configs_from_cache () {
+        yield move_config_from_cache ("unattended");
+        yield move_config_from_cache ("sources");
+    }
+
+    private async void move_config_from_cache (string config_name) {
+        var path = get_cache (config_name);
+        var cache_dir = File.new_for_path (path);
+        var config_path = Path.build_filename (get_user_pkgconfig (), config_name);
+
+        try {
+            var enumerator = yield cache_dir.enumerate_children_async (FileAttribute.STANDARD_NAME, 0);
+            while (true) {
+                var files = yield enumerator.next_files_async (10);
+                if (files == null)
+                    break;
+
+                foreach (var info in files) {
+                    path = Path.build_filename (cache_dir.get_path (), info.get_name ());
+                    var cache_file = File.new_for_path (path);
+                    path = Path.build_filename (config_path, info.get_name ());
+                    var config_file = File.new_for_path (path);
+
+                    cache_file.move (config_file, FileCopyFlags.OVERWRITE);
+                    print ("moved %s to %s\n", cache_file.get_path (), config_file.get_path ());
+                }
+            }
+
+            yield cache_dir.delete_async ();
+        } catch (IOError.NOT_FOUND error) {
+            // That just means config doesn't exist in cache dir
+        } catch (GLib.Error error) {
+            warning (error.message);
+        }
+    }
+
     namespace UUID {
         [CCode (cname = "uuid_generate", cheader_filename = "uuid/uuid.h")]
         internal extern static void generate ([CCode (array_length = false)] uchar[] uuid);


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