From 1e847f5242cdcd426a0bb8f87ea5009481f990ec Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Mon, 27 Jun 2011 00:28:56 +0200 Subject: [PATCH] Fixed bug 698565. Added g_access calls to f_save and o_save to abort saving if the destination file is read-only. --- libgeda/src/a_basic.c | 9 +++++++++ libgeda/src/f_basic.c | 8 ++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/libgeda/src/a_basic.c b/libgeda/src/a_basic.c index 2868891..4d839ff 100644 --- a/libgeda/src/a_basic.c +++ b/libgeda/src/a_basic.c @@ -226,6 +226,15 @@ int o_save (TOPLEVEL *toplevel, const GList *object_list, { char *buffer; + /* Check to see if real filename is writable; if file doesn't exists + we assume all is well */ + if (g_file_test(filename, G_FILE_TEST_EXISTS) && + g_access(filename, W_OK) != 0) { + g_set_error (err, G_FILE_ERROR, G_FILE_ERROR_PERM, + _("File %s is read-only"), filename); + return 0; + } + buffer = o_save_buffer (toplevel, object_list); if (!g_file_set_contents (filename, buffer, strlen(buffer), err)) { g_free (buffer); diff --git a/libgeda/src/f_basic.c b/libgeda/src/f_basic.c index a843b33..3621715 100644 --- a/libgeda/src/f_basic.c +++ b/libgeda/src/f_basic.c @@ -373,6 +373,14 @@ int f_save(TOPLEVEL *toplevel, PAGE *page, const char *filename, GError **err) tmp_err->message); return 0; } + + /* Check to see if filename is writable */ + if (g_file_test(filename, G_FILE_TEST_EXISTS) && + g_access(filename, W_OK) != 0) { + g_set_error (err, G_FILE_ERROR, G_FILE_ERROR_PERM, + _("File %s is read-only"), filename); + return 0; + } /* Get the directory in which the real filename lives */ dirname = g_path_get_dirname (real_filename); -- 1.7.0.4