From 406260fe13c11537e395a13d194569d7827a8b8a Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 7 Dec 2014 11:29:16 +0300 Subject: [PATCH] Check that we can write to the file before we do (Bug #11307) If the user set the directory to read-only to prevent new sessions from being saved xfsm ends up trying to write to read-only files. --- xfce4-session/xfsm-manager.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/xfce4-session/xfsm-manager.c b/xfce4-session/xfsm-manager.c index dc2960e..4b14f10 100644 --- a/xfce4-session/xfsm-manager.c +++ b/xfce4-session/xfsm-manager.c @@ -1652,6 +1652,8 @@ xfsm_manager_store_session (XfsmManager *manager) GdkDisplay *display; WnckScreen *screen; XfceRc *rc; + GFile *session_file; + GFileInfo *info; GList *lp; gchar prefix[64]; gchar *backup; @@ -1659,6 +1661,7 @@ xfsm_manager_store_session (XfsmManager *manager) gint count = 0; gint n, m; + /* open file for writing, creates it if it doesn't exist */ rc = xfce_rc_simple_open (manager->session_file, FALSE); if (G_UNLIKELY (rc == NULL)) { @@ -1670,6 +1673,32 @@ xfsm_manager_store_session (XfsmManager *manager) return; } + session_file = g_file_new_for_path (manager->session_file); + + /* query the file, we need to make sure we can write to it */ + info = g_file_query_info (session_file, + G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); + + /* if we're unable to query the file attributes or write to the file, + * log the failure and return */ + if (!info || !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) + { + fprintf (stderr, + "xfce4-session: Unable to save changes to the session file %s" + "Please check your installation.\n", manager->session_file); + + if (info) + g_object_unref (info); + + xfce_rc_close (rc); + g_object_unref (session_file); + + return; + } + /* backup the old session file first */ if (g_file_test (manager->session_file, G_FILE_TEST_IS_REGULAR)) { @@ -1743,6 +1772,8 @@ xfsm_manager_store_session (XfsmManager *manager) xfce_rc_close (rc); + g_object_unref (session_file); + g_free (manager->checkpoint_session_name); manager->checkpoint_session_name = NULL; } -- 2.2.0