summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-01-02 14:20:10 -0500
committerRyan Lortie <desrt@desrt.ca>2013-01-02 14:21:22 -0500
commita2bad17d26b596ef46fd2e9c60b9e0163a51012d (patch)
treefede0ee2a08dadb20c0eb911f1c261a812a91506
parentd5e6b6d16c47c4a97bf5b9ab34054f5d26e456af (diff)
downloaddconf-a2bad17d26b596ef46fd2e9c60b9e0163a51012d.tar.gz
service: try mkdir_with_parents() on failed writes
If we fail to write the database file, try g_mkdir_with_parents() to create the parent directory and try again. https://bugzilla.gnome.org/show_bug.cgi?id=689136
-rw-r--r--service/dconf-gvdb-utils.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/service/dconf-gvdb-utils.c b/service/dconf-gvdb-utils.c
index 9e0c4b1..a9b7ab4 100644
--- a/service/dconf-gvdb-utils.c
+++ b/service/dconf-gvdb-utils.c
@@ -160,6 +160,22 @@ dconf_gvdb_utils_write_file (const gchar *filename,
gvdb = gvdb_hash_table_new (NULL, NULL);
dconf_changeset_all (database, dconf_gvdb_utils_add_key, gvdb);
success = gvdb_table_write_contents (gvdb, filename, FALSE, error);
+
+ if (!success)
+ {
+ gchar *dirname;
+
+ /* Maybe it failed because the directory doesn't exist. Try
+ * again, after mkdir().
+ */
+ dirname = g_path_get_dirname (filename);
+ g_mkdir_with_parents (dirname, 0777);
+ g_free (dirname);
+
+ g_clear_error (error);
+ success = gvdb_table_write_contents (gvdb, filename, FALSE, error);
+ }
+
g_hash_table_unref (gvdb);
return success;