]> git.cworth.org Git - notmuch/commitdiff
lib/open: canonicalize relative path read from config file
authorDavid Bremner <david@tethera.net>
Wed, 3 Mar 2021 12:31:44 +0000 (08:31 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 27 Mar 2021 12:26:14 +0000 (09:26 -0300)
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

index 6c3ef46fe5a620d9f00ffffd2947858e33efab51..d0493950ff0d48877c8536b0f6535110bde2bbe0 100644 (file)
@@ -196,11 +196,13 @@ _choose_database_path (void *ctx,
     if (! *database_path && key_file) {
        char *path = g_key_file_get_value (key_file, "database", "path", NULL);
        if (path) {
-           *database_path = talloc_strdup (ctx, 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;