diff options
author | Claudio Saavedra <csaavedra@igalia.com> | 2013-01-23 19:54:21 +0800 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2013-01-27 23:59:17 +0800 |
commit | fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749 (patch) | |
tree | de20729e84c87c13117fb017cdd6ab1f06df0b5d /lib | |
parent | 76de6c62ecf84b26e703ebe8eefa8fb55eec807e (diff) | |
download | gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.tar gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.tar.gz gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.tar.bz2 gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.tar.lz gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.tar.xz gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.tar.zst gsoc2013-epiphany-fdf27e6538f0aefb1f5d1f7fcc72d6e3668b8749.zip |
ephy-node-db: use g_file_set_contents() when saving to disk
Since g_file_set_contents() is atomic and already takes care of saving
first to a temporary file, we don't need to use
ephy_file_switch_temp_file().
https://bugzilla.gnome.org/show_bug.cgi?id=691794
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ephy-node-db.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/ephy-node-db.c b/lib/ephy-node-db.c index 1a80e779f..94efd76eb 100644 --- a/lib/ephy-node-db.c +++ b/lib/ephy-node-db.c @@ -358,7 +358,7 @@ ephy_node_db_load_from_file (EphyNodeDb *db, static int ephy_node_db_write_to_xml_valist (EphyNodeDb *db, - const xmlChar *filename, + xmlBuffer *buffer, const xmlChar *root, const xmlChar *version, const xmlChar *comment, @@ -374,7 +374,7 @@ ephy_node_db_write_to_xml_valist (EphyNodeDb *db, START_PROFILER ("Saving node db") /* FIXME: do we want to turn compression on ? */ - writer = xmlNewTextWriterFilename ((const char *)filename, 0); + writer = xmlNewTextWriterMemory (buffer, 0); if (writer == NULL) { return -1; @@ -487,36 +487,33 @@ ephy_node_db_write_to_xml_safe (EphyNodeDb *db, EphyNode *node, ...) { va_list argptr; + xmlBuffer *buffer; + GError *error = NULL; int ret = 0; - GFile *tmp_file, *file; - char *tmp_file_path; - - tmp_file_path = g_strconcat ((const gchar *) filename, ".tmp", NULL); - tmp_file = g_file_new_for_path (tmp_file_path); - file = g_file_new_for_path ((const char *) filename); va_start (argptr, node); - + + buffer = xmlBufferCreate (); ret = ephy_node_db_write_to_xml_valist - (db, (const xmlChar *)tmp_file_path, root, version, comment, node, argptr); + (db, buffer, root, version, comment, node, argptr); va_end (argptr); if (ret < 0) { - g_warning ("Failed to write XML data to %s", tmp_file_path); + g_warning ("Failed to write XML data"); goto failed; } - if (ephy_file_switch_temp_file (file, tmp_file) == FALSE) + if (g_file_set_contents ((const char *)filename, (const char *)buffer->content, buffer->use, &error) == FALSE) { + g_warning ("Error saving EphyNodeDB as XML: %s", error->message); + g_error_free (error); ret = -1; } failed: - g_free (tmp_file_path); - g_object_unref (file); - g_object_unref (tmp_file); + xmlBufferFree (buffer); return ret; } |