[PATCH 09/27] lib/open: canonicalize relative path read from config file

Subject: [PATCH 09/27] lib/open: canonicalize relative path read from config file

Date: Thu, 4 Mar 2021 09:01:21 -0400

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


This matches functionality in the the CLI function
notmuch_config_get_database_path, which was previously used in the CLI
code for all calls to open a database.
---
 lib/open.cc | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/open.cc b/lib/open.cc
index 58385592..737e79a7 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -193,9 +193,16 @@ _choose_database_path (void * ctx,
        *database_path = getenv ("NOTMUCH_DATABASE");
     }
 
-    if (! *database_path && key_file)
-	*database_path = g_key_file_get_value (key_file, "database", "path", NULL);
-
+    if (! *database_path && key_file) {
+	gchar *path = g_key_file_get_value (key_file, "database", "path", NULL);
+	if (path) {
+	    if (path[0] == '/')
+		*database_path = talloc_strdup (ctx, path);
+	    else
+		*database_path = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), path);
+	    g_free (path);
+	}
+    }
     if (! *database_path) {
 	*database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile);
 	*split = true;
-- 
2.30.1
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: