diff options
author | Havoc Pennington <hp@src.gnome.org> | 2002-06-01 21:30:36 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2002-06-01 21:30:36 +0000 |
commit | 17a83d083c1bbd9f9983f3dcd5d2e45b0e97f8b5 (patch) | |
tree | 4c38e97f92a654c6e2e81cc5272710882c61f4fc | |
parent | f6d04a8d5c901c376f6d2dd89f5c6ea89c95e3e1 (diff) | |
download | gconf-17a83d083c1bbd9f9983f3dcd5d2e45b0e97f8b5.tar.gz |
sync, lightning storm ;-)
-rw-r--r-- | backends/markup-tree.c | 98 | ||||
-rw-r--r-- | tests/testbackend.c | 154 |
2 files changed, 227 insertions, 25 deletions
diff --git a/backends/markup-tree.c b/backends/markup-tree.c index 0c58ab47..d5d0ab4b 100644 --- a/backends/markup-tree.c +++ b/backends/markup-tree.c @@ -488,6 +488,8 @@ markup_dir_ensure_entry (MarkupDir *dir, if (entry != NULL) return entry; + g_return_val_if_fail (dir->entries_loaded, NULL); + /* Create a new entry */ entry = markup_entry_new (dir, relative_key); dir->entries = g_slist_prepend (dir->entries, entry); @@ -540,9 +542,11 @@ markup_dir_ensure_subdir (MarkupDir *dir, if (subdir == NULL) { + g_return_val_if_fail (dir->subdirs_loaded, NULL); + subdir = markup_dir_new (dir->tree, dir, relative_key); subdir->entries_need_save = TRUE; /* so we save empty %gconf.xml */ - + /* we don't need to load stuff, since we know the dir didn't exist */ subdir->entries_loaded = TRUE; subdir->subdirs_loaded = TRUE; @@ -657,12 +661,14 @@ create_filesystem_dir (const char *name, return TRUE; } -static void +static gboolean delete_useless_subdirs (MarkupDir *dir) { GSList *tmp; GSList *kept_subdirs; + gboolean some_deleted; + some_deleted = FALSE; kept_subdirs = NULL; tmp = dir->subdirs; @@ -701,25 +707,60 @@ delete_useless_subdirs (MarkupDir *dir) g_free (fs_filename); markup_dir_free (subdir); + + some_deleted = TRUE; } else { + if (subdir->entries == NULL && subdir->subdirs == NULL) + { + char *fs_filename; + struct stat statbuf; + + fs_filename = markup_dir_build_path (subdir, TRUE); + + if (stat (fs_filename, &statbuf) < 0) + { + /* This is some kind of cruft, not an XML directory */ + g_printerr ("failed to stat %s: %s\n", fs_filename, g_strerror (errno)); + } + else + { + load_subdirs (subdir); + if (statbuf.st_size == 0 && subdir->subdirs == NULL) + { + g_print ("Not deleting %s entries_loaded = %d subdirs_loaded = %d " + "subdir_needs_sync = %d entries_need_save = %d; %d entries %d subdirs\n", + subdir->name, subdir->entries_loaded, subdir->subdirs_loaded, + subdir->some_subdir_needs_sync, subdir->entries_need_save, + g_slist_length (subdir->entries), + g_slist_length (subdir->subdirs)); + exit (1); + } + } + g_free (fs_filename); + } kept_subdirs = g_slist_prepend (kept_subdirs, subdir); } - + tmp = tmp->next; } - + g_slist_free (dir->subdirs); dir->subdirs = g_slist_reverse (kept_subdirs); -} -static void + return some_deleted; +} + +static gboolean delete_useless_entries (MarkupDir *dir) { GSList *tmp; GSList *kept_entries; + gboolean some_deleted; + some_deleted = FALSE; + kept_entries = NULL; tmp = dir->entries; @@ -734,6 +775,7 @@ delete_useless_entries (MarkupDir *dir) entry->schema_name == NULL) { markup_entry_free (entry); + some_deleted = TRUE; } else { @@ -745,6 +787,8 @@ delete_useless_entries (MarkupDir *dir) g_slist_free (dir->entries); dir->entries = g_slist_reverse (kept_entries); + + return some_deleted; } static gboolean @@ -753,7 +797,25 @@ markup_dir_sync (MarkupDir *dir) char *fs_dirname; char *fs_filename; GSList *tmp; + gboolean some_useless_entries; + gboolean some_useless_subdirs; + + some_useless_entries = FALSE; + some_useless_subdirs = FALSE; + { + MarkupDir *parent; + + parent = dir->parent; + while (parent) + { + fputs (" ", stdout); + parent = parent->parent; + } + + g_print ("%s\n", dir->name); + } + /* We assume our parent directories have all been synced, before * we are synced. So we don't need to mkdir() parent directories. */ @@ -784,7 +846,8 @@ markup_dir_sync (MarkupDir *dir) g_return_val_if_fail (dir->entries_loaded, FALSE); - delete_useless_entries (dir); + if (delete_useless_entries (dir)) + some_useless_entries = TRUE; /* Be sure the directory exists */ if (!dir->filesystem_dir_probably_exists) @@ -855,11 +918,30 @@ markup_dir_sync (MarkupDir *dir) * we're deleting our subdirs, the root dir (tree->root) * never gets deleted - this is intentional. */ - delete_useless_subdirs (dir); + if (delete_useless_subdirs (dir)) + some_useless_subdirs = TRUE; g_free (fs_dirname); g_free (fs_filename); + + /* If we deleted an entry or subdir from this directory, and hadn't + * fully loaded this directory, we now don't know whether the entry + * or subdir was the last thing making the directory worth keeping + * around. So we need to load so we can be established as useless if + * necessary. + */ + if (some_useless_entries && !dir->subdirs_loaded) + { + g_assert (dir->entries_loaded); + load_subdirs (dir); + } + if (some_useless_subdirs && !dir->entries_loaded) + { + g_assert (dir->subdirs_loaded); + load_entries (dir); + } + return !markup_dir_needs_sync (dir); } diff --git a/tests/testbackend.c b/tests/testbackend.c index 69c75347..718293fb 100644 --- a/tests/testbackend.c +++ b/tests/testbackend.c @@ -380,6 +380,53 @@ set_bool (GConfSource *source, return ret; } +static gboolean +set_float (GConfSource *source, + const char *key, + double v, + GError **err) +{ + GConfValue *value; + gboolean ret; + + value = gconf_value_new (GCONF_VALUE_FLOAT); + gconf_value_set_float (value, v); + ret = set_value (source, key, value, err); + gconf_value_free (value); + return ret; +} + +static gboolean +set_list (GConfSource *source, + const char *key, + GConfValueType list_type, + GSList *list, + GError **err) +{ + GConfValue *value_list; + GError *tmp_err = NULL; + gboolean ret; + + g_return_val_if_fail (source != NULL, FALSE); + g_return_val_if_fail (key != NULL, FALSE); + g_return_val_if_fail (list_type != GCONF_VALUE_INVALID, FALSE); + g_return_val_if_fail (list_type != GCONF_VALUE_LIST, FALSE); + g_return_val_if_fail (list_type != GCONF_VALUE_PAIR, FALSE); + g_return_val_if_fail (err == NULL || *err == NULL, FALSE); + + value_list = gconf_value_list_from_primitive_list (list_type, list, &tmp_err); + + if (tmp_err) + { + g_propagate_error (err, tmp_err); + return FALSE; + } + + ret = set_value (source, key, value_list, err); + gconf_value_free (value_list); + return ret; +} + static GConfValue* get_value (GConfSource *source, const char *key, @@ -400,6 +447,7 @@ get_string (GConfSource *source, if (val) { + g_assert (val->type == GCONF_VALUE_STRING); s = gconf_value_steal_string (val); gconf_value_free (val); } @@ -423,6 +471,7 @@ get_bool (GConfSource *source, if (val) { + g_assert (val->type == GCONF_VALUE_BOOL); b = gconf_value_get_bool (val); gconf_value_free (val); } @@ -434,6 +483,80 @@ get_bool (GConfSource *source, return b; } +static int +get_int (GConfSource *source, + const char *key, + GError **err) +{ + GConfValue *val; + int i; + + val = get_value (source, key, err); + + if (val) + { + g_assert (val->type == GCONF_VALUE_INT); + i = gconf_value_get_int (val); + gconf_value_free (val); + } + else + { + i = FALSE; + } + + return i; +} + +static double +get_float (GConfSource *source, + const char *key, + GError **err) +{ + GConfValue *val; + double d; + + val = get_value (source, key, err); + + if (val) + { + g_assert (val->type == GCONF_VALUE_FLOAT); + d = gconf_value_get_float (val); + gconf_value_free (val); + } + else + { + d = FALSE; + } + + return d; +} + +static GSList* +get_list (GConfSource *source, + const char *key, + GConfValueType list_type, + GError **err) +{ + GConfValue* val; + + g_return_val_if_fail (source != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + g_return_val_if_fail (list_type != GCONF_VALUE_INVALID, NULL); + g_return_val_if_fail (list_type != GCONF_VALUE_LIST, NULL); + g_return_val_if_fail (list_type != GCONF_VALUE_PAIR, NULL); + g_return_val_if_fail (err == NULL || *err == NULL, NULL); + + val = get_value (source, key, err); + + if (val == NULL) + return NULL; + else + { + /* This type-checks the value */ + return gconf_value_list_to_primitive_list_destructive (val, list_type, err); + } +} + static void check_string_storage (GConfSource *source) { @@ -647,7 +770,6 @@ check_bool_storage (GConfSource *source) void check_float_storage (GConfSource *source) { -#if 0 GError* err = NULL; const char** keyp = NULL; guint i; @@ -664,7 +786,7 @@ check_float_storage (GConfSource *source) { gdouble gotten; - if (!gconf_engine_set_float (source, *keyp, floats[i], &err)) + if (!set_float (source, *keyp, floats[i], &err)) { g_printerr ("Failed to set key `%s' to `%g': %s\n", *keyp, floats[i], err->message); @@ -675,7 +797,7 @@ check_float_storage (GConfSource *source) { sync_and_clear (source); - gotten = gconf_engine_get_float (source, *keyp, &err); + gotten = get_float (source, *keyp, &err); if (err != NULL) { @@ -713,7 +835,7 @@ check_float_storage (GConfSource *source) { gdouble gotten; - if (!gconf_engine_set_float (source, *keyp, floats[i], &err)) + if (!set_float (source, *keyp, floats[i], &err)) { g_printerr ("Failed to set key `%s' to `%g': %s\n", *keyp, floats[i], err->message); @@ -724,7 +846,7 @@ check_float_storage (GConfSource *source) { sync_and_clear (source); - gotten = gconf_engine_get_float (source, *keyp, &err); + gotten = get_float (source, *keyp, &err); if (err != NULL) { @@ -752,13 +874,11 @@ check_float_storage (GConfSource *source) } check_unset (source); -#endif } void check_int_storage (GConfSource *source) { -#if 0 GError* err = NULL; const char** keyp = NULL; guint i; @@ -774,7 +894,7 @@ check_int_storage (GConfSource *source) { gint gotten; - if (!gconf_engine_set_int (source, *keyp, ints[i], &err)) + if (!set_int (source, *keyp, ints[i], &err)) { g_printerr ("Failed to set key `%s' to `%d': %s\n", *keyp, ints[i], err->message); @@ -785,7 +905,7 @@ check_int_storage (GConfSource *source) { sync_and_clear (source); - gotten = gconf_engine_get_int (source, *keyp, &err); + gotten = get_int (source, *keyp, &err); if (err != NULL) { @@ -823,7 +943,7 @@ check_int_storage (GConfSource *source) { gint gotten; - if (!gconf_engine_set_int (source, *keyp, ints[i], &err)) + if (!set_int (source, *keyp, ints[i], &err)) { g_printerr ("Failed to set key `%s' to `%d': %s\n", *keyp, ints[i], err->message); @@ -834,7 +954,7 @@ check_int_storage (GConfSource *source) { sync_and_clear (source); - gotten = gconf_engine_get_int (source, *keyp, &err); + gotten = get_int (source, *keyp, &err); if (err != NULL) { @@ -862,7 +982,6 @@ check_int_storage (GConfSource *source) } check_unset (source); -#endif } static void @@ -1011,7 +1130,6 @@ list_of_floats (void) static void check_list_storage (GConfSource *source) { -#if 0 GError* err = NULL; const char** keyp = NULL; guint i; @@ -1052,7 +1170,7 @@ check_list_storage (GConfSource *source) { GSList* gotten = NULL; - if (!gconf_engine_set_list (source, *keyp, list_types[i], lists[i], &err)) + if (!set_list (source, *keyp, list_types[i], lists[i], &err)) { g_printerr ("Failed to set key `%s' to list: %s\n", *keyp, err->message); @@ -1063,7 +1181,7 @@ check_list_storage (GConfSource *source) { sync_and_clear (source); - gotten = gconf_engine_get_list (source, *keyp, list_types[i], &err); + gotten = get_list (source, *keyp, list_types[i], &err); if (err != NULL) { @@ -1094,7 +1212,6 @@ check_list_storage (GConfSource *source) } check_unset (source); -#endif } typedef struct @@ -1161,6 +1278,8 @@ main (int argc, char **argv) return 1; } + g_assert (source != NULL); + stats.entry_count = 0; foreach_recursive (source, "/", 0, print_entry, &stats); @@ -1185,11 +1304,12 @@ main (int argc, char **argv) g_print ("\nChecking bool storage:"); check_bool_storage (source); + + sync_and_clear (source); gconf_source_free (source); g_print ("\n\n"); - return 0; } |