gnucash maint: Revisit "Bug 741810 - Compilation fails because of creating .gnucash"

Geert Janssens gjanssens at code.gnucash.org
Wed Dec 24 06:36:24 EST 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/24dff859 (commit)
	from  https://github.com/Gnucash/gnucash/commit/3ae0c780 (commit)



commit 24dff8598599cb9979924b9226f1c7acabc7a6bd
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Wed Dec 24 12:49:46 2014 +0100

    Revisit "Bug 741810 - Compilation fails because of creating .gnucash"
    
    Use the temp dir as base dir for .gnucash
    in all cases where the home dir fails. This
    is more than just if the home directory doesn't exist.
    
    Also don't attempt to create the home directory.

diff --git a/src/core-utils/gnc-filepath-utils.c b/src/core-utils/gnc-filepath-utils.c
index 54cdc18..11d5ecf 100644
--- a/src/core-utils/gnc-filepath-utils.c
+++ b/src/core-utils/gnc-filepath-utils.c
@@ -300,7 +300,7 @@ gnc_path_find_localized_html_file (const gchar *file_name)
  * @param dirname The path to check
  */
 static gboolean
-gnc_validate_directory (const gchar *dirname, gchar **msg)
+gnc_validate_directory (const gchar *dirname, gboolean create, gchar **msg)
 {
     struct stat statbuf;
     gint rc;
@@ -312,21 +312,33 @@ gnc_validate_directory (const gchar *dirname, gchar **msg)
         switch (errno)
         {
         case ENOENT:
-            rc = g_mkdir (dirname,
+            if (create)
+            {
+                rc = g_mkdir (dirname,
 #ifdef G_OS_WIN32
-                          0          /* The mode argument is ignored on windows */
+                              0          /* The mode argument is ignored on windows */
 #else
-                          S_IRWXU    /* perms = S_IRWXU = 0700 */
+                              S_IRWXU    /* perms = S_IRWXU = 0700 */
 #endif
-                         );
-            if (rc)
+                              );
+                if (rc)
+                {
+                    *msg = g_strdup_printf(
+                            _("An error occurred while creating the directory:\n"
+                              "  %s\n"
+                              "Please correct the problem and restart GnuCash.\n"
+                              "The reported error was '%s' (errno %d).\n"),
+                              dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
+                    return FALSE;
+                }
+            }
+            else
             {
                 *msg = g_strdup_printf(
-                          _("An error occurred while creating the directory:\n"
-                            "  %s\n"
-                            "Please correct the problem and restart GnuCash.\n"
-                            "The reported error was '%s' (errno %d).\n"),
-                          dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
+                        _("Note: the directory\n"
+                          "  %s\n"
+                          "doesn't exist. This is however not fatal.\n"),
+                          dirname);
                 return FALSE;
             }
             g_stat (dirname, &statbuf);
@@ -412,7 +424,7 @@ gnc_dotgnucash_dir (void)
     if (!dotgnucash)
     {
         const gchar *home = g_get_home_dir();
-        if (!home || !gnc_validate_directory(home, &errmsg))
+        if (!home || !gnc_validate_directory(home, FALSE, &errmsg))
         {
             g_free(errmsg);
             g_warning("Cannot find suitable home directory. Using tmp directory instead.");
@@ -422,20 +434,31 @@ gnc_dotgnucash_dir (void)
 
         dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
     }
-    if (!gnc_validate_directory(dotgnucash, &errmsg))
-        exit(1);
+    if (!gnc_validate_directory(dotgnucash, TRUE, &errmsg))
+    {
+        const gchar *tmp = g_get_tmp_dir();
+        g_free(errmsg);
+        g_free(dotgnucash);
+        g_warning("Cannot find suitable .gnucash directory in home directory. Using tmp directory instead.");
+        g_assert(tmp);
+
+        dotgnucash = g_build_filename(tmp, ".gnucash", (gchar *)NULL);
+        
+        if (!gnc_validate_directory(dotgnucash, TRUE, &errmsg))
+            exit(1);
+    }
 
     /* Since we're in code that is only executed once.... */
     tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
-    if (!gnc_validate_directory(tmp_dir, &errmsg))
+    if (!gnc_validate_directory(tmp_dir, TRUE, &errmsg))
         exit(1);
     g_free(tmp_dir);
     tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
-    if (!gnc_validate_directory(tmp_dir, &errmsg))
+    if (!gnc_validate_directory(tmp_dir, TRUE, &errmsg))
         exit(1);
     g_free(tmp_dir);
     tmp_dir = g_build_filename(tmp_dir, "translog", (gchar *)NULL);
-    if (!gnc_validate_directory(dotgnucash, &errmsg))
+    if (!gnc_validate_directory(dotgnucash, TRUE, &errmsg))
         exit(1);
     g_free(tmp_dir);
 



Summary of changes:
 src/core-utils/gnc-filepath-utils.c | 57 ++++++++++++++++++++++++++-----------
 1 file changed, 40 insertions(+), 17 deletions(-)



More information about the gnucash-changes mailing list