gnucash maint: Bug 794916 - Fails to find environment file at startup when installation prefix is '/opt'

Geert Janssens gjanssens at code.gnucash.org
Mon Apr 16 17:25:52 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/87f94abc (commit)
	from  https://github.com/Gnucash/gnucash/commit/5e807a0e (commit)



commit 87f94abc8d5a7276ec1fb0d2a527295a59169a7d
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Mon Apr 16 23:25:37 2018 +0200

    Bug 794916 - Fails to find environment file at startup when installation prefix is '/opt'

diff --git a/libgnucash/core-utils/binreloc.c b/libgnucash/core-utils/binreloc.c
index 1b7b1b6..34c0e27 100644
--- a/libgnucash/core-utils/binreloc.c
+++ b/libgnucash/core-utils/binreloc.c
@@ -567,9 +567,43 @@ gnc_gbr_find_etc_dir (const gchar *default_etc_dir)
             return NULL;
     }
 
-    sysconfdir = gnc_file_path_relative_part(PREFIX, SYSCONFDIR);
-    dir = g_build_filename (prefix, sysconfdir, NULL);
-    g_free (sysconfdir);
+    if (g_path_is_absolute (SYSCONFDIR))
+    {
+        sysconfdir = gnc_file_path_relative_part("/", SYSCONFDIR);
+        dir = g_build_filename (prefix, sysconfdir, NULL);
+        g_free (sysconfdir);
+    }
+    else if ((g_strcmp0 (PREFIX, "/opt") == 0) ||
+             (g_str_has_prefix (PREFIX, "/opt/")))
+    {
+        /* If the prefix is "/opt/..." the etc stuff will be installed in
+         * "SYSCONFDIR/opt/...", while the rest will be in "/opt/..."
+         * If this gets relocated after (make install), there will be another
+         * prefix prepended to all of that:
+         * "prefix2/opt/..."
+         * "prefix2/SYSCONFDIR/opt/..."
+         * Note: this most likely won't work on Windows. Don't try a /opt
+         * prefix on that platform...
+         */
+        gchar *std_etc_dir = g_build_filename ("/", SYSCONFDIR, PREFIX, NULL);
+
+        gchar *base_prefix_pos = g_strstr_len (prefix, -1, PREFIX);
+        if (!base_prefix_pos || base_prefix_pos == prefix)
+            dir = g_build_filename ("/", std_etc_dir, NULL);
+        else
+        {
+            gchar *prefix2 = g_strndup (prefix, base_prefix_pos - prefix);
+            dir = g_build_filename (prefix2, std_etc_dir, NULL);
+        }
+        g_free (std_etc_dir);
+
+    }
+    else
+    {
+        sysconfdir = gnc_file_path_relative_part(PREFIX, SYSCONFDIR);
+        dir = g_build_filename (prefix, sysconfdir, NULL);
+        g_free (sysconfdir);
+    }
     g_free (prefix);
     return dir;
 }



Summary of changes:
 libgnucash/core-utils/binreloc.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list