[evolution-data-server] server_side_source_write(): Create parent directories.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] server_side_source_write(): Create parent directories.
- Date: Fri, 10 Aug 2012 11:42:25 +0000 (UTC)
commit 1c1f1352917abe8b46088963952dc5d4a7d58020
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Aug 9 20:12:44 2012 -0400
server_side_source_write(): Create parent directories.
Had a situation while restoring from a backup tarball where the
"sources" directory was getting deleted and consequently causing
g_file_replace_contents() to fail. So always make the directory
immediately before writing the key file to disk.
libebackend/e-server-side-source.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/libebackend/e-server-side-source.c b/libebackend/e-server-side-source.c
index 9c4ca5f..553c9d6 100644
--- a/libebackend/e-server-side-source.c
+++ b/libebackend/e-server-side-source.c
@@ -858,16 +858,14 @@ server_side_source_write (ESource *source,
if (replace_file) {
GFile *file;
+ GFile *write_directory;
gchar *basename;
- gchar *filename;
g_warn_if_fail (priv->write_directory != NULL);
basename = g_file_get_basename (priv->file);
- filename = g_build_filename (
- priv->write_directory, basename, NULL);
- file = g_file_new_for_path (filename);
- g_free (filename);
+ write_directory = g_file_new_for_path (priv->write_directory);
+ file = g_file_get_child (write_directory, basename);
g_free (basename);
if (!g_file_equal (file, priv->file)) {
@@ -877,9 +875,17 @@ server_side_source_write (ESource *source,
server_side_source_print_diff (source, old_data, new_data);
- g_file_replace_contents (
- file, new_data, strlen (new_data), NULL, FALSE,
- G_FILE_CREATE_NONE, NULL, cancellable, &error);
+ g_file_make_directory_with_parents (
+ write_directory, cancellable, &error);
+
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+ g_clear_error (&error);
+
+ if (error == NULL)
+ g_file_replace_contents (
+ file, new_data, strlen (new_data),
+ NULL, FALSE, G_FILE_CREATE_NONE,
+ NULL, cancellable, &error);
if (error == NULL) {
g_free (priv->file_contents);
@@ -887,6 +893,7 @@ server_side_source_write (ESource *source,
new_data = NULL;
}
+ g_object_unref (write_directory);
g_object_unref (file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]