aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-05-26 03:39:09 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-05-26 03:39:09 +0800
commit9ae7960ca8c3ca534ba07bb6d58b430ee9cda413 (patch)
tree552cf6c6fded80d05acaea44eeef46f7509d21ad /lib
parentc159006b08ac492649715c9a3ce55f258e199f97 (diff)
downloadgsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.tar
gsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.tar.gz
gsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.tar.bz2
gsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.tar.lz
gsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.tar.xz
gsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.tar.zst
gsoc2013-epiphany-9ae7960ca8c3ca534ba07bb6d58b430ee9cda413.zip
Try to fix node removal problems. I cant repro crashes ... but they are
2003-05-25 Marco Pesenti Gritti <marco@it.gnome.org> * configure.in: * embed/ephy-favicon-cache.c: (ephy_favicon_cache_save): * embed/ephy-history.c: (ephy_history_save), (hosts_removed_cb), (pages_removed_cb), (unref_empty_host), (page_removed_from_host_cb), (connect_page_removed_from_host), (ephy_history_init), (ephy_history_add_host): * lib/ephy-file-helpers.c: (ephy_file_save_xml): * lib/ephy-file-helpers.h: * lib/ephy-node.c: (callback), (ephy_node_emit_signal), (real_remove_child), (ephy_node_dispose): * lib/ephy-node.h: * lib/ephy-state.c: (ephy_states_save): * lib/widgets/ephy-tree-model-node.c: (root_child_removed_cb): * src/bookmarks/ephy-bookmarks-export.c: (ephy_bookmarks_export_rdf): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_save), (bookmarks_removed_cb), (topics_removed_cb): Try to fix node removal problems. I cant repro crashes ... but they are quite hard to reproduce. Use a save_xml helper that is low disk safe. * src/ephy-automation.c: (impl_ephy_automation_loadurl): Use OPEN_PAGE when an url is passed
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-file-helpers.c57
-rw-r--r--lib/ephy-file-helpers.h4
-rw-r--r--lib/ephy-node.c56
-rw-r--r--lib/ephy-node.h2
-rw-r--r--lib/ephy-state.c2
-rw-r--r--lib/widgets/ephy-tree-model-node.c5
6 files changed, 102 insertions, 24 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 6ca68be28..6577bc06b 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -365,3 +365,60 @@ ephy_file_find (const char *path,
ephy_find_file_recursive (path, fname, &ret, 0, maxdepth);
return ret;
}
+
+gboolean
+ephy_file_save_xml (const char *xml_file, xmlDocPtr doc)
+{
+ char *tmp_file;
+ char *old_file;
+ gboolean old_exist;
+ gboolean retval = TRUE;
+
+ tmp_file = g_strconcat (xml_file, ".tmp", NULL);
+ old_file = g_strconcat (xml_file, ".old", NULL);
+
+ if (!xmlSaveFormatFile (tmp_file, doc, 1))
+ {
+ g_warning ("Failed to write XML data to %s", tmp_file);
+ goto failed;
+ }
+
+ old_exist = g_file_test (xml_file, G_FILE_TEST_EXISTS);
+
+ if (old_exist)
+ {
+ if (rename (xml_file, old_file) < 0)
+ {
+ g_warning ("Failed to rename %s to %s", xml_file, old_file);
+ retval = FALSE;
+ goto failed;
+ }
+ }
+
+ if (rename (tmp_file, xml_file) < 0)
+ {
+ g_warning ("Failed to rename %s to %s", tmp_file, xml_file);
+
+ if (rename (old_file, xml_file) < 0)
+ {
+ g_warning ("Failed to restore %s from %s", xml_file, tmp_file);
+ }
+ retval = FALSE;
+ goto failed;
+ }
+
+ if (old_exist)
+ {
+ if (unlink (old_file) < 0)
+ {
+ g_warning ("Failed to delete old file %s", old_file);
+ }
+ }
+
+ failed:
+ g_free (old_file);
+ g_free (tmp_file);
+
+ return retval;
+}
+
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 0fb24b254..cd29f9ec4 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -22,6 +22,7 @@
#define EPHY_FILE_HELPERS_H
#include <glib.h>
+#include <libxml/tree.h>
G_BEGIN_DECLS
@@ -46,6 +47,9 @@ GSList *ephy_file_find (const char *path,
const char *fname,
gint maxdepth);
+gboolean ephy_file_save_xml (const char *xml_file,
+ xmlDocPtr doc);
+
G_END_DECLS
#endif /* EPHY_FILE_HELPERS_H */
diff --git a/lib/ephy-node.c b/lib/ephy-node.c
index 660b234ee..35c7f87d6 100644
--- a/lib/ephy-node.c
+++ b/lib/ephy-node.c
@@ -129,10 +129,21 @@ callback (long id, EphyNodeSignalData *data, gpointer *user_data)
case EPHY_NODE_CHILD_ADDED:
case EPHY_NODE_CHILD_CHANGED:
- case EPHY_NODE_CHILD_REMOVED:
data->callback (data->node, va_arg (valist, EphyNode *), data->data);
break;
+ case EPHY_NODE_CHILD_REMOVED:
+ {
+ EphyNode *node;
+ guint last_index;
+
+ node = va_arg (valist, EphyNode *);
+ last_index = va_arg (valist, guint);
+
+ data->callback (data->node, node, last_index, data->data);
+ }
+ break;
+
case EPHY_NODE_CHILDREN_REORDERED:
data->callback (data->node, va_arg (valist, int *), data->data);
break;
@@ -152,6 +163,7 @@ ephy_node_emit_signal (EphyNode *node, EphyNodeSignalType type, ...)
g_hash_table_foreach (node->signals,
(GHFunc) callback,
data);
+
va_end (valist);
}
@@ -197,6 +209,9 @@ real_remove_child (EphyNode *node,
if (remove_from_parent) {
guint i;
+ guint old_index;
+
+ old_index = node_info->index;
g_ptr_array_remove_index (node->children,
node_info->index);
@@ -216,21 +231,20 @@ real_remove_child (EphyNode *node,
g_static_rw_lock_writer_unlock (borked_node->lock);
}
+
+ write_lock_to_read_lock (node);
+ write_lock_to_read_lock (child);
+
+ ephy_node_emit_signal (node, EPHY_NODE_CHILD_REMOVED, child, old_index);
+
+ read_lock_to_write_lock (node);
+ read_lock_to_write_lock (child);
}
if (remove_from_child) {
g_hash_table_remove (child->parents,
GINT_TO_POINTER (node->id));
}
-
- write_lock_to_read_lock (node);
- write_lock_to_read_lock (child);
-
- ephy_node_emit_signal (node, EPHY_NODE_CHILD_REMOVED, child);
-
- read_lock_to_write_lock (node);
- read_lock_to_write_lock (child);
-
}
static void
@@ -267,19 +281,8 @@ ephy_node_dispose (EphyNode *node)
{
guint i;
- _ephy_node_db_remove_id (node->db, node->id);
-
lock_gdk ();
- /* remove from DAG */
- g_hash_table_foreach (node->parents,
- (GHFunc) remove_child,
- node);
-
- g_hash_table_foreach (node->signals,
- (GHFunc) unref_signal_objects,
- node);
-
for (i = 0; i < node->children->len; i++) {
EphyNode *child;
@@ -292,10 +295,21 @@ ephy_node_dispose (EphyNode *node)
g_static_rw_lock_writer_unlock (child->lock);
}
+ /* remove from DAG */
+ g_hash_table_foreach (node->parents,
+ (GHFunc) remove_child,
+ node);
+
g_static_rw_lock_writer_unlock (node->lock);
ephy_node_emit_signal (node, EPHY_NODE_DESTROYED);
+ g_hash_table_foreach (node->signals,
+ (GHFunc) unref_signal_objects,
+ node);
+
+ _ephy_node_db_remove_id (node->db, node->id);
+
unlock_gdk ();
}
diff --git a/lib/ephy-node.h b/lib/ephy-node.h
index 846d5fa41..5a6853f4e 100644
--- a/lib/ephy-node.h
+++ b/lib/ephy-node.h
@@ -34,7 +34,7 @@ typedef enum
EPHY_NODE_RESTORED, /* RBNode *node */
EPHY_NODE_CHILD_ADDED, /* RBNode *node, RBNode *child */
EPHY_NODE_CHILD_CHANGED, /* RBNode *node, RBNode *child */
- EPHY_NODE_CHILD_REMOVED, /* RBNode *node, RBNode *child */
+ EPHY_NODE_CHILD_REMOVED, /* RBNode *node, RBNode *child, guint old_index */
EPHY_NODE_CHILDREN_REORDERED /* RBNode *node, int *new_order */
} EphyNodeSignalType;
diff --git a/lib/ephy-state.c b/lib/ephy-state.c
index 1df65a642..a23533ae4 100644
--- a/lib/ephy-state.c
+++ b/lib/ephy-state.c
@@ -109,7 +109,7 @@ ephy_states_save (void)
}
ephy_node_thaw (states);
- xmlSaveFormatFile (xml_file, doc, 1);
+ ephy_file_save_xml (xml_file, doc);
g_free (xml_file);
}
diff --git a/lib/widgets/ephy-tree-model-node.c b/lib/widgets/ephy-tree-model-node.c
index 73c654712..cf92167d2 100644
--- a/lib/widgets/ephy-tree-model-node.c
+++ b/lib/widgets/ephy-tree-model-node.c
@@ -66,6 +66,7 @@ static gboolean ephy_tree_model_node_iter_parent (GtkTreeModel *tree_model,
static void ephy_tree_model_node_tree_model_init (GtkTreeModelIface *iface);
static void root_child_removed_cb (EphyNode *node,
EphyNode *child,
+ guint old_index,
EphyTreeModelNode *model);
static void root_child_added_cb (EphyNode *node,
EphyNode *child,
@@ -656,11 +657,13 @@ ephy_tree_model_node_iter_from_node (EphyTreeModelNode *model,
static void
root_child_removed_cb (EphyNode *node,
EphyNode *child,
+ guint old_index,
EphyTreeModelNode *model)
{
GtkTreePath *path;
- path = get_path_real (model, child);
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, old_index);
gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
gtk_tree_path_free (path);
}