diff options
author | Colin Walters <walters@verbum.org> | 2013-05-09 16:48:03 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-05-09 16:48:03 -0400 |
commit | 4f01c0b159409727e736b841c5ca0d3d6b60da6c (patch) | |
tree | 7f08a66b4af1f77f492bb8bdfc2703d16c3af002 /gtk/gtkbookmarksmanager.c | |
parent | 20e86751067743f3469d90739b494cc3b753a75d (diff) | |
download | gtk+-4f01c0b159409727e736b841c5ca0d3d6b60da6c.tar.gz |
GtkBookmarksManager: Ensure parent directory exists when saving
Otherwise we fail when the user doesn't have ~/.config yet.
Diffstat (limited to 'gtk/gtkbookmarksmanager.c')
-rw-r--r-- | gtk/gtkbookmarksmanager.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/gtk/gtkbookmarksmanager.c b/gtk/gtkbookmarksmanager.c index 91ccd89c29..e475ea0756 100644 --- a/gtk/gtkbookmarksmanager.c +++ b/gtk/gtkbookmarksmanager.c @@ -115,6 +115,7 @@ save_bookmarks (GFile *bookmarks_file, GError *error = NULL; GString *contents; GSList *l; + GFile *parent = NULL; contents = g_string_new (""); @@ -136,16 +137,28 @@ save_bookmarks (GFile *bookmarks_file, g_free (uri); } + parent = g_file_get_parent (bookmarks_file); + if (!g_file_make_directory_with_parents (parent, NULL, &error)) + { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) + g_clear_error (&error); + else + goto out; + } if (!g_file_replace_contents (bookmarks_file, contents->str, strlen (contents->str), NULL, FALSE, 0, NULL, NULL, &error)) + goto out; + + out: + if (error) { g_critical ("%s", error->message); g_error_free (error); } - + g_clear_object (&parent); g_string_free (contents, TRUE); } |