[recipes] Don't create an empty chef for the user



commit 0ead639f14acd8d357a11feb9d1d65ed21255f1a
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 7 16:45:33 2016 -0500

    Don't create an empty chef for the user

 src/gr-recipe-store.c |   57 ++++++++++++++----------------------------------
 1 files changed, 17 insertions(+), 40 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index eb507e1..5671d6f 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -805,27 +805,23 @@ save_chefs (GrRecipeStore *store)
 }
 
 static void
-ensure_user (GrRecipeStore *self)
+save_user (GrRecipeStore *self)
 {
-        g_autoptr(GrChef) chef = NULL;
-        g_autoptr(GError) error = NULL;
+        g_autofree char *path = NULL;
 
-        self->user = g_strdup (g_get_user_name ());
-        chef = g_hash_table_lookup (self->chefs, self->user);
-        if (chef) {
-                g_message ("Found chef for user name: %s", self->user);
-                g_object_ref (chef);
+        path = g_build_filename (get_user_data_dir (), "user", NULL);
+
+        g_message ("Save user id: %s", path);
+
+        if (self->user == NULL || self->user[0] == '\0') {
+                g_unlink (path);
         }
         else {
-                g_message ("Create chef for user name: %s", self->user);
-                // TODO get the users avatar - needs an account portal
-                chef = g_object_new (GR_TYPE_CHEF,
-                                     "name", self->user,
-                                     "fullname", g_get_real_name (),
-                                     NULL);
-        }
-        if (!gr_recipe_store_update_user (self, chef, &error)) {
-                g_warning ("Failed to store chef for user name: %s", error->message);
+                g_autoptr(GError) error = NULL;
+
+                if (!g_file_set_contents (path, self->user, -1, &error)) {
+                        g_error ("Failed to save user id: %s", error->message);
+                }
         }
 }
 
@@ -841,8 +837,10 @@ load_user (GrRecipeStore *self,
         if (!g_file_get_contents (path, &contents, NULL, &error)) {
                 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
                         g_error ("Failed to load user id: %s", error->message);
-                else
-                        ensure_user (self);
+                else {
+                        self->user = g_strdup (g_get_user_name ());
+                        save_user (self);
+                }
                 return;
         }
 
@@ -855,27 +853,6 @@ load_user (GrRecipeStore *self,
 }
 
 static void
-save_user (GrRecipeStore *self)
-{
-        g_autofree char *path = NULL;
-
-        path = g_build_filename (get_user_data_dir (), "user", NULL);
-
-        g_message ("Save user id: %s", path);
-
-        if (self->user == NULL || self->user[0] == '\0') {
-                g_unlink (path);
-        }
-        else {
-                g_autoptr(GError) error = NULL;
-
-                if (!g_file_set_contents (path, self->user, -1, &error)) {
-                        g_error ("Failed to save user id: %s", error->message);
-                }
-        }
-}
-
-static void
 gr_recipe_store_init (GrRecipeStore *self)
 {
         const char *dir;


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