r20099 - gnucash/trunk/src - Bug 639322 part 2: display an error message if a user attempts to save beneath gnc_dotgnucash_dir

Geert Janssens gjanssens at code.gnucash.org
Fri Jan 14 16:47:27 EST 2011


Author: gjanssens
Date: 2011-01-14 16:47:27 -0500 (Fri, 14 Jan 2011)
New Revision: 20099
Trac: http://svn.gnucash.org/trac/changeset/20099

Modified:
   gnucash/trunk/src/gnome-utils/gnc-file.c
   gnucash/trunk/src/libqof/qof/qofbackend.h
Log:
Bug 639322 part 2: display an error message if a user attempts to save beneath gnc_dotgnucash_dir

Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c	2011-01-14 21:47:14 UTC (rev 20098)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c	2011-01-14 21:47:27 UTC (rev 20099)
@@ -34,6 +34,7 @@
 #include "gnc-engine.h"
 #include "Account.h"
 #include "gnc-file.h"
+#include "gnc-filepath-utils.h"
 #include "gnc-gui-query.h"
 #include "gnc-hooks.h"
 #include "gnc-keyring.h"
@@ -398,6 +399,13 @@
         gnc_error_dialog (parent, fmt, displayname);
         break;
 
+    case ERR_FILEIO_RESERVED_WRITE:
+        fmt = _("You attempted to save in\n%s\nor a subdirectory thereof.  "
+                "This is not allowed as %s reserves that directory for internal use.\n\n"
+                "Please try again in a different directory.");
+        gnc_error_dialog (parent, fmt, gnc_dotgnucash_dir(), PACKAGE_NAME);
+        break;
+
     case ERR_SQL_DB_TOO_OLD:
         fmt = _("This database is from an older version of GnuCash. "
                 "Do you want to want to upgrade the database "
@@ -1210,12 +1218,23 @@
         newfile = norm_file;
     }
 
-    /* For file based uri's, remember the directory as the default. */
+    /* Some extra steps for file based uri's only */
     if (gnc_uri_is_file_protocol(protocol))
     {
+        /* Remember the directory as the default. */
         gchar *default_dir = g_path_get_dirname(path);
         gnc_set_default_directory (GCONF_DIR_OPEN_SAVE, default_dir);
         g_free(default_dir);
+
+        /* Prevent user to store file in GnuCash' private configuration
+         * directory (~/.gnucash by default in linux, but can be overridden)
+         */
+        DEBUG("User path: %s, dotgnucash_dir: %s", path, gnc_dotgnucash_dir());
+        if (g_str_has_prefix(path, gnc_dotgnucash_dir()))
+        {
+            show_session_error (ERR_FILEIO_RESERVED_WRITE, newfile, GNC_FILE_DIALOG_SAVE);
+            return;
+        }
     }
 
     /* Check to see if the user specified the same file as the current

Modified: gnucash/trunk/src/libqof/qof/qofbackend.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbackend.h	2011-01-14 21:47:14 UTC (rev 20098)
+++ gnucash/trunk/src/libqof/qof/qofbackend.h	2011-01-14 21:47:27 UTC (rev 20099)
@@ -96,6 +96,8 @@
     ERR_FILEIO_READ_ERROR,     /**< Could not open the file for reading. */
     ERR_FILEIO_NO_ENCODING,    /**< file does not specify encoding */
     ERR_FILEIO_FILE_EACCES,    /**< No read access permission for the given file */
+    ERR_FILEIO_RESERVED_WRITE, /**< User attempt to write to a directory reserved
+                                    for internal use by GnuCash */
 
     /* network errors */
     ERR_NETIO_SHORT_READ = 2000,  /**< not enough bytes received */



More information about the gnucash-changes mailing list