[recipes/image-download: 13/13] Add version information to the keyfiles
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/image-download: 13/13] Add version information to the keyfiles
- Date: Sun, 2 Apr 2017 17:07:39 +0000 (UTC)
commit 789b30241c8e585d52a8e0edce0543a63dcb7cfc
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 2 12:04:21 2017 -0400
Add version information to the keyfiles
This is just to prepare for the eventuality that
we may have to make changes to the key file format
in the future.
src/gr-recipe-store.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index e75787c..d7f339f 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -183,6 +183,7 @@ load_recipes (GrRecipeStore *self,
g_auto(GStrv) groups = NULL;
gsize length, length2;
int i, j;
+ int version;
keyfile = g_key_file_new ();
@@ -195,8 +196,26 @@ load_recipes (GrRecipeStore *self,
g_info ("No recipe db at: %s", path);
return FALSE;
}
+
g_info ("Load recipe db: %s", path);
+ version = g_key_file_get_integer (keyfile, "Metadata", "Version", &error);
+ if (error) {
+ if (g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) ||
+ g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) {
+ g_info ("No metadata found, assuming version 1");
+ version = 1;
+ }
+ else {
+ g_error ("Failed to read recipe db: %s", error->message);
+ return FALSE;
+ }
+ g_clear_error (&error);
+ }
+ if (version != 1) {
+ g_error ("Don't know how to handle recipe db version %d", version);
+ }
+
groups = g_key_file_get_groups (keyfile, &length);
for (i = 0; i < length; i++) {
GrRecipe *recipe;
@@ -222,6 +241,9 @@ load_recipes (GrRecipeStore *self,
g_autoptr(GDateTime) mtime = NULL;
char *tmp;
+ if (strcmp (groups[i], "Metadata") == 0)
+ continue;
+
g_clear_error (&error);
id = groups[i];
@@ -488,6 +510,8 @@ save_recipes (GrRecipeStore *self)
g_info ("Save recipe db: %s", path);
+ g_key_file_set_integer (keyfile, "Metadata", "Version", 1);
+
keys = g_hash_table_get_keys (self->recipes);
keys = g_list_sort (keys, (GCompareFunc)strcmp);
for (l = keys; l; l = l->next) {
@@ -711,6 +735,7 @@ load_chefs (GrRecipeStore *self,
g_auto(GStrv) groups = NULL;
gsize length;
int i;
+ int version;
keyfile = g_key_file_new ();
@@ -731,6 +756,23 @@ load_chefs (GrRecipeStore *self,
g_info ("Load chefs db: %s", path);
+ version = g_key_file_get_integer (keyfile, "Metadata", "Version", &error);
+ if (error) {
+ if (g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) ||
+ g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) {
+ g_info ("No metadata found, assuming version 1");
+ version = 1;
+ }
+ else {
+ g_error ("Failed to read chefs db: %s", error->message);
+ return FALSE;
+ }
+ g_clear_error (&error);
+ }
+ if (version != 1) {
+ g_error ("Don't know how to handle chefs db version %d", version);
+ }
+
groups = g_key_file_get_groups (keyfile, &length);
for (i = 0; i < length; i++) {
GrChef *chef;
@@ -740,6 +782,9 @@ load_chefs (GrRecipeStore *self,
g_autofree char *description = NULL;
g_autofree char *image_path = NULL;
+ if (strcmp (groups[i], "Metadata") == 0)
+ continue;
+
g_clear_error (&error);
id = groups[i];
@@ -814,6 +859,8 @@ save_chefs (GrRecipeStore *store)
g_info ("Save chefs db: %s", path);
+ g_key_file_set_integer (keyfile, "Metadata", "Version", 1);
+
keys = g_hash_table_get_keys (store->chefs);
keys = g_list_sort (keys, (GCompareFunc)strcmp);
for (l = keys; l; l = l->next) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]