r20100 - gnucash/trunk/src/gnome-utils - Bug 639322 part 2b: display an error message if a user attempts to export to somewhere in gnc_dotgnucash_dir

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


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

Modified:
   gnucash/trunk/src/gnome-utils/gnc-file.c
Log:
Bug 639322 part 2b: display an error message if a user attempts to export to somewhere in gnc_dotgnucash_dir
and add a hint for translators to the error message string

Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c	2011-01-14 21:47:27 UTC (rev 20099)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c	2011-01-14 21:47:35 UTC (rev 20100)
@@ -400,6 +400,9 @@
         break;
 
     case ERR_FILEIO_RESERVED_WRITE:
+        /* Translators: the first %s is a path in the filesystem,
+         * the second %s is PACKAGE_NAME, which by default is "GnuCash"
+         */
         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.");
@@ -1004,12 +1007,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_EXPORT, default_dir);
+        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



More information about the gnucash-changes mailing list