static Dir* dir_blank(const gchar* key) { Dir* d; d = g_new0(Dir, 1); #ifdef GCONF_ENABLE_DEBUG { gchar* why; if (!gconf_valid_key(key, &why)) { gconf_log(GCL_DEBUG, "key `%s' invalid: %s", key, why); } g_assert(gconf_valid_key(key, NULL)); } #endif d->key = g_strdup (key); d->parent_key = gconf_key_directory (key); d->last_access = time(NULL); d->doc = NULL; d->entry_cache = g_hash_table_new (g_str_hash, g_str_equal); d->dirty = FALSE; d->need_rescan_subdirs = TRUE; d->subdir_names = NULL; d->dir_mode = 0700; d->file_mode = 0600; return d; }
Dir* dir_load (const gchar* key, const gchar* xml_root_dir, GError** err) { Dir* d; gchar* fs_dirname; gchar* xml_filename; guint dir_mode = 0700; guint file_mode = 0600; g_return_val_if_fail(gconf_valid_key(key, NULL), NULL); fs_dirname = gconf_concat_dir_and_key(xml_root_dir, key); xml_filename = g_strconcat(fs_dirname, "/%gconf.xml", NULL); { struct stat s; gboolean notfound = FALSE; if (g_stat(xml_filename, &s) != 0) { if (errno != ENOENT) { gconf_set_error (err, GCONF_ERROR_FAILED, _("Could not stat `%s': %s"), xml_filename, g_strerror(errno)); } notfound = TRUE; } else if (S_ISDIR(s.st_mode)) { gconf_set_error (err, GCONF_ERROR_FAILED, _("XML filename `%s' is a directory"), xml_filename); notfound = TRUE; } if (notfound) { gconf_log(GCL_DEBUG, "dir file %s not found", xml_filename); g_free(fs_dirname); g_free(xml_filename); return NULL; } else { /* Take directory mode from the xml_root_dir, if possible */ if (g_stat (xml_root_dir, &s) == 0) { dir_mode = _gconf_mode_t_to_mode (s.st_mode); } file_mode = dir_mode & ~0111; /* turn off search bits */ } } d = dir_blank(key); /* sync with dir_new() */ d->fs_dirname = fs_dirname; d->xml_filename = xml_filename; d->root_dir_len = strlen(xml_root_dir); d->dir_mode = dir_mode; d->file_mode = file_mode; gconf_log (GCL_DEBUG, "loaded dir %s", fs_dirname); return d; }
void entry_fill_from_node(Entry* e) { gchar* tmp; GError* error = NULL; g_return_if_fail(e->node != NULL); tmp = my_xmlGetProp(e->node, "schema"); if (tmp != NULL) { /* Filter any crap schemas that appear, some speed cost */ gchar* why_bad = NULL; if (gconf_valid_key(tmp, &why_bad)) { g_assert(why_bad == NULL); e->schema_name = g_strdup(tmp); } else { e->schema_name = NULL; gconf_log(GCL_WARNING, _("Ignoring schema name `%s', invalid: %s"), tmp, why_bad); g_free(why_bad); } xmlFree(tmp); } tmp = my_xmlGetProp(e->node, "mtime"); if (tmp != NULL) { e->mod_time = gconf_string_to_gulong(tmp); xmlFree(tmp); } else e->mod_time = 0; tmp = my_xmlGetProp(e->node, "muser"); if (tmp != NULL) { e->mod_user = g_strdup(tmp); xmlFree(tmp); } else e->mod_user = NULL; entry_sync_if_needed(e); if (e->cached_value != NULL) gconf_value_free(e->cached_value); e->cached_value = node_extract_value(e->node, NULL, /* FIXME current locale as a guess */ &error); if (e->cached_value) { g_return_if_fail(error == NULL); return; } else if (error != NULL) { /* Ignore errors from node_extract_value() if we got a schema name, * since the node's only purpose may be to store the schema name. */ if (e->schema_name == NULL) gconf_log (GCL_WARNING, _("Ignoring XML node `%s': %s"), e->name, error->message); g_error_free(error); } }