[PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME

David Edmondson dme at dme.org
Sat Sep 8 02:22:53 PDT 2018


On Friday, 2018-09-07 at 21:10:42 -03, David Bremner wrote:

> David Edmondson <dme at dme.org> writes:
>
>> If the database path specified in the configuration file does *not*
>> start with a /, presume that it is relative to $HOME and modify the
>> path used to open the database accordingly.
>> ---
>>  notmuch-config.c | 14 +++++++++++++-
>>  1 file changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/notmuch-config.c b/notmuch-config.c
>> index e1b16609..bf77cc9d 100644
>> --- a/notmuch-config.c
>> +++ b/notmuch-config.c
>> @@ -660,7 +660,19 @@ _config_set_list (notmuch_config_t *config,
>>  const char *
>>  notmuch_config_get_database_path (notmuch_config_t *config)
>>  {
>> -    return _config_get (config, &config->database_path, "database", "path");
>> +    char *db_path = (char *)_config_get (config, &config->database_path, "database", "path");
>> +
>> +    if (db_path && *db_path != '/') {
>> +	/* If the path in the configuration file begins with any
>> +	 * character other than /, presume that it is relative to
>> +	 * $HOME and update as appropriate.
>> +	 */
>> +	char *abs_path = talloc_asprintf (config, "%s/%s", getenv ("HOME"), db_path);
>> +	talloc_free (db_path);
>> +	db_path = config->database_path = abs_path;
>> +    }
>
> In the unlikely event that HOME is not set, it would be nicer to print a
> message to that effect, rather than

I did think about that, but decided to follow existing practice in
notmuch, which doesn't check:

        config->filename = talloc_asprintf (config, "%s/.notmuch-config",
                                            getenv ("HOME"));

...and...

            path = talloc_asprintf (config, "%s/mail",
                                    getenv ("HOME"));

>   configuration file (null)/.notmuch-config not found.
>   Try running 'notmuch setup' to create a configuration.

dme.
-- 
It's funny, I spent my whole life wanting to be talked about.


More information about the notmuch mailing list