[nautilus] bookmark-list: Add an error handler of saving bookmark list



commit 5adf0129f6332592059a175c88e870f135bc6830
Author: Yi-Soo An <yisooan gmail com>
Date:   Wed Nov 28 12:36:40 2018 +0900

    bookmark-list: Add an error handler of saving bookmark list
    
    For arbitrary reasons, g_mkdir_with_parents can be failed.
    That could lead to an error that fails to replace contents of
    new bookmark list.

 src/nautilus-bookmark-list.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-bookmark-list.c b/src/nautilus-bookmark-list.c
index 54d52626b..ad25b66d6 100644
--- a/src/nautilus-bookmark-list.c
+++ b/src/nautilus-bookmark-list.c
@@ -31,6 +31,7 @@
 
 #include <gio/gio.h>
 #include <string.h>
+#include <errno.h>
 
 #define MAX_BOOKMARK_LENGTH 80
 #define LOAD_JOB 1
@@ -54,12 +55,20 @@ enum
 static guint signals[LAST_SIGNAL];
 
 /* forward declarations */
+#define NAUTILUS_BOOKMARK_LIST_ERROR (nautilus_bookmark_list_error_quark())
+static GQuark      nautilus_bookmark_list_error_quark (void);
 
 static void        nautilus_bookmark_list_load_file (NautilusBookmarkList *bookmarks);
 static void        nautilus_bookmark_list_save_file (NautilusBookmarkList *bookmarks);
 
 G_DEFINE_TYPE (NautilusBookmarkList, nautilus_bookmark_list, G_TYPE_OBJECT)
 
+static GQuark
+nautilus_bookmark_list_error_quark (void)
+{
+    return g_quark_from_static_string ("nautilus-bookmark-list-error-quark");
+}
+
 static NautilusBookmark *
 new_bookmark_from_uri (const char *uri, const char *label)
 {
@@ -458,7 +467,15 @@ save_io_thread (GTask        *task,
     parent = g_file_get_parent (file);
     path = g_file_get_path (parent);
 
-    g_mkdir_with_parents (path, 0700);
+    if (g_mkdir_with_parents (path, 0700) == -1) {
+        int saved_errno = errno;
+
+        g_set_error (&error, NAUTILUS_BOOKMARK_LIST_ERROR, 0,
+                     "Failed to create bookmarks folder %s: %s",
+                     path, g_strerror (saved_errno));
+        g_task_return_error (task, error);
+        return;
+    }
 
     contents = (gchar *) g_task_get_task_data (task);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]