unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: Re: [PATCH 2/9] lib/config: canonicalize paths relative to $HOME.
Date: Fri, 07 May 2021 15:28:56 +0300	[thread overview]
Message-ID: <m24kfeiv7b.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20210507113029.2685184-3-david@tethera.net>

On Fri, May 07 2021, David Bremner wrote:

> Prior to 0.32, notmuch had the (undocumented) behaviour that it
> expanded a relative value of database.path with respect to $HOME. In
> 0.32 this was special cased for database.path but broken for
> database.mail_root, which causes problems for at least notmuch-new
> when database.path is set to a relative path.
>
> The change in T030-config.sh reflects a user visible, but hopefully
> harmless behaviour change; the expanded form of the paths will now be
> printed by notmuch config.
> ---
>  lib/config.cc       | 22 +++++++++++++++++++++-
>  test/T030-config.sh |  6 +++---
>  test/T050-new.sh    |  1 -
>  3 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/lib/config.cc b/lib/config.cc
> index 50bcf6a2..e08c6bf7 100644
> --- a/lib/config.cc
> +++ b/lib/config.cc
> @@ -387,6 +387,23 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs)
>      talloc_free (pairs);
>  }
>  
> +static char *
> +_expand_path (void *ctx, const char *key, const char *val)
> +{
> +    char *expanded_val;
> +
> +    if ((strcmp (key, "database.path") == 0 ||
> +	 strcmp (key, "database.mail_root") == 0 ||
> +	 strcmp (key, "database.hook_dir") == 0 ||
> +	 strcmp (key, "database.backup_path") == 0 ) &&
> +	val[0] != '/')

check val[0] first then one does not need to waste time scanning
through all the other possible values for 'key'. that is trivial
"optimization", other possible but not worth the effort...

> +	expanded_val = talloc_asprintf (ctx, "%s/%s", getenv("HOME"), val);
> +    else
> +	expanded_val = talloc_strdup (ctx, val);
> +
> +    return expanded_val;
> +}
> +
>  notmuch_status_t
>  _notmuch_config_load_from_file (notmuch_database_t *notmuch,
>  				GKeyFile *file)
> @@ -407,14 +424,17 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
>  	keys = g_key_file_get_keys (file, *grp, NULL, NULL);
>  	for (gchar **keys_p = keys; *keys_p; keys_p++) {
>  	    char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp,  *keys_p);
> +	    char *normalized_val;
>  	    val = g_key_file_get_value (file, *grp, *keys_p, NULL);
>  	    if (! val) {
>  		status = NOTMUCH_STATUS_FILE_ERROR;
>  		goto DONE;
>  	    }
> -	    _notmuch_string_map_set (notmuch->config, absolute_key, val);
> +	    normalized_val = _expand_path (notmuch, absolute_key, val);
> +	    _notmuch_string_map_set (notmuch->config, absolute_key, normalized_val);
>  	    g_free (val);
>  	    talloc_free (absolute_key);
> +	    talloc_free (normalized_val);
>  	    if (status)
>  		goto DONE;
>  	}
> diff --git a/test/T030-config.sh b/test/T030-config.sh
> index b22d8f29..7a1660e9 100755
> --- a/test/T030-config.sh
> +++ b/test/T030-config.sh
> @@ -117,12 +117,12 @@ test_expect_equal "$(notmuch config get database.path)" \
>  
>  ln -s `pwd`/mail home/Maildir
>  add_email_corpus
> -test_begin_subtest "Relative database path expanded in open"
> +test_begin_subtest "Relative database path expanded"
>  notmuch config set database.path Maildir
> -path=$(notmuch config get database.path)
> +path=$(notmuch config get database.path | notmuch_dir_sanitize)
>  count=$(notmuch count '*')
>  test_expect_equal "${path} ${count}" \
> -		  "Maildir 52"
> +		  "CWD/home/Maildir 52"
>  
>  test_begin_subtest "Add config to database"
>  notmuch new
> diff --git a/test/T050-new.sh b/test/T050-new.sh
> index 5faf6839..33ad7f5a 100755
> --- a/test/T050-new.sh
> +++ b/test/T050-new.sh
> @@ -395,7 +395,6 @@ EOF
>  test_expect_equal_file EXPECTED OUTPUT
>  
>  test_begin_subtest "Relative database path expanded in new"
> -test_subtest_known_broken
>  ln -s `pwd`/mail home/Maildir
>  notmuch config set database.path Maildir
>  generate_message
> -- 
> 2.30.2
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

  reply	other threads:[~2021-05-07 12:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 11:30 Restore relative path handling for database.path David Bremner
2021-05-07 11:30 ` [PATCH 1/9] test: add known broken test for relative database path in new David Bremner
2021-05-07 12:19   ` Tomi Ollila
2021-05-07 11:30 ` [PATCH 2/9] lib/config: canonicalize paths relative to $HOME David Bremner
2021-05-07 12:28   ` Tomi Ollila [this message]
2021-05-07 16:16     ` Tomi Ollila
2021-05-07 11:30 ` [PATCH 3/9] test: add known broken test for relative setting of mail_root David Bremner
2021-05-07 11:30 ` [PATCH 4/9] lib/config: expand relative paths when reading from database David Bremner
2021-05-07 12:30   ` Tomi Ollila
2021-05-07 11:30 ` [PATCH 5/9] test: test relative paths for database.hook_dir David Bremner
2021-05-07 12:34   ` Tomi Ollila
2021-05-07 11:30 ` [PATCH 6/9] test: test explicit configuration of backup directory David Bremner
2021-05-07 11:30 ` [PATCH 7/9] doc: document (tersely) the intended behaviour of relative paths David Bremner
2021-05-07 15:31   ` David Edmondson
2021-05-07 11:30 ` [PATCH 8/9] doc: document database.backup_dir David Bremner
2021-05-07 11:30 ` [PATCH 9/9] NEWS: start NEWS for 0.32.1 David Bremner
2021-05-10 14:42 ` Restore relative path handling for database.path David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m24kfeiv7b.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).