unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v1 0/2] Interpret a directory path without a leading slash as relative to $HOME.
@ 2018-08-25 11:57 David Edmondson
  2018-08-25 11:57 ` [PATCH v1 1/2] test: Absolute and relative directory paths David Edmondson
  2018-08-25 11:57 ` [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME David Edmondson
  0 siblings, 2 replies; 9+ messages in thread
From: David Edmondson @ 2018-08-25 11:57 UTC (permalink / raw)
  To: notmuch


Being able to specify a database path that works well on multiple
machines, where $HOME is not always the same, seems generally
useful.

There was a previous attempt to support ~ in the configuration file
(id:1462722574-4176-1-git-send-email-bijan@chokoufe.com), but this
foundered on concerns about support for ~otheruser.

This patch attempts to avoid that problem by asserting that any
database lacking a leading / character is interpreted as being
relative to $HOME.

So in my case, I would set the path to Maildir:

[database]
path=Maildir

This would work in Linux (where my home directory is /home/dme) and on
macOS (where it is /Users/dme).

David Edmondson (2):
  test: Absolute and relative directory paths.
  notmuch: Database paths without a leading / are relative to $HOME

 notmuch-config.c    | 14 +++++++++++++-
 test/T030-config.sh | 10 ++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v1 1/2] test: Absolute and relative directory paths.
  2018-08-25 11:57 [PATCH v1 0/2] Interpret a directory path without a leading slash as relative to $HOME David Edmondson
@ 2018-08-25 11:57 ` David Edmondson
  2018-09-08  0:05   ` David Bremner
  2018-08-25 11:57 ` [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME David Edmondson
  1 sibling, 1 reply; 9+ messages in thread
From: David Edmondson @ 2018-08-25 11:57 UTC (permalink / raw)
  To: notmuch

---
 test/T030-config.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/test/T030-config.sh b/test/T030-config.sh
index e91c3659..f36695c6 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -99,4 +99,14 @@ test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
 test_begin_subtest "Writing config file through symlink follows symlink"
 test_expect_equal "$(readlink alt-config-link)" "alt-config"
 
+test_begin_subtest "Absolute database path returned"
+notmuch config set database.path ${HOME}/Maildir
+test_expect_equal "$(notmuch config get database.path)" \
+		  "${HOME}/Maildir"
+
+test_begin_subtest "Relative database path properly expanded"
+notmuch config set database.path Maildir
+test_expect_equal "$(notmuch config get database.path)" \
+		  "${HOME}/Maildir"
+
 test_done
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME
  2018-08-25 11:57 [PATCH v1 0/2] Interpret a directory path without a leading slash as relative to $HOME David Edmondson
  2018-08-25 11:57 ` [PATCH v1 1/2] test: Absolute and relative directory paths David Edmondson
@ 2018-08-25 11:57 ` David Edmondson
  2018-09-08  0:10   ` David Bremner
  1 sibling, 1 reply; 9+ messages in thread
From: David Edmondson @ 2018-08-25 11:57 UTC (permalink / raw)
  To: notmuch

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;
+    }
+
+    return db_path;
 }
 
 void
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] test: Absolute and relative directory paths.
  2018-08-25 11:57 ` [PATCH v1 1/2] test: Absolute and relative directory paths David Edmondson
@ 2018-09-08  0:05   ` David Bremner
  2018-09-08  9:22     ` David Edmondson
  0 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2018-09-08  0:05 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

> ---
>  test/T030-config.sh | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/test/T030-config.sh b/test/T030-config.sh
> index e91c3659..f36695c6 100755
> --- a/test/T030-config.sh
> +++ b/test/T030-config.sh
> @@ -99,4 +99,14 @@ test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
>  test_begin_subtest "Writing config file through symlink follows symlink"
>  test_expect_equal "$(readlink alt-config-link)" "alt-config"
>  
> +test_begin_subtest "Absolute database path returned"
> +notmuch config set database.path ${HOME}/Maildir
> +test_expect_equal "$(notmuch config get database.path)" \
> +		  "${HOME}/Maildir"
> +
> +test_begin_subtest "Relative database path properly expanded"
> +notmuch config set database.path Maildir
> +test_expect_equal "$(notmuch config get database.path)" \
> +		  "${HOME}/Maildir"
> +
>  test_done
> -- 

We want the test suite to pass after every commit, so you need to either
squash the second test into the next commit, or mark it with
test_subtest_known_broken. I'm fine with either option.

d

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME
  2018-08-25 11:57 ` [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME David Edmondson
@ 2018-09-08  0:10   ` David Bremner
  2018-09-08  9:22     ` David Edmondson
  0 siblings, 1 reply; 9+ messages in thread
From: David Bremner @ 2018-09-08  0:10 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@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

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] test: Absolute and relative directory paths.
  2018-09-08  0:05   ` David Bremner
@ 2018-09-08  9:22     ` David Edmondson
  2018-09-08 10:27       ` David Bremner
  0 siblings, 1 reply; 9+ messages in thread
From: David Edmondson @ 2018-09-08  9:22 UTC (permalink / raw)
  To: David Bremner, notmuch

On Friday, 2018-09-07 at 21:05:38 -03, David Bremner wrote:

> David Edmondson <dme@dme.org> writes:
>
>> ---
>>  test/T030-config.sh | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/test/T030-config.sh b/test/T030-config.sh
>> index e91c3659..f36695c6 100755
>> --- a/test/T030-config.sh
>> +++ b/test/T030-config.sh
>> @@ -99,4 +99,14 @@ test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
>>  test_begin_subtest "Writing config file through symlink follows symlink"
>>  test_expect_equal "$(readlink alt-config-link)" "alt-config"
>>  
>> +test_begin_subtest "Absolute database path returned"
>> +notmuch config set database.path ${HOME}/Maildir
>> +test_expect_equal "$(notmuch config get database.path)" \
>> +		  "${HOME}/Maildir"
>> +
>> +test_begin_subtest "Relative database path properly expanded"
>> +notmuch config set database.path Maildir
>> +test_expect_equal "$(notmuch config get database.path)" \
>> +		  "${HOME}/Maildir"
>> +
>>  test_done
>> -- 
>
> We want the test suite to pass after every commit, so you need to either
> squash the second test into the next commit, or mark it with
> test_subtest_known_broken. I'm fine with either option.

Would you be happy with me just re-arranging the order, so that the test
came after?

dme.
-- 
Sorry I'm not home right now, I'm walking into spiderwebs.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME
  2018-09-08  0:10   ` David Bremner
@ 2018-09-08  9:22     ` David Edmondson
  2018-09-08 10:28       ` David Bremner
  0 siblings, 1 reply; 9+ messages in thread
From: David Edmondson @ 2018-09-08  9:22 UTC (permalink / raw)
  To: David Bremner, notmuch

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

> David Edmondson <dme@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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 1/2] test: Absolute and relative directory paths.
  2018-09-08  9:22     ` David Edmondson
@ 2018-09-08 10:27       ` David Bremner
  0 siblings, 0 replies; 9+ messages in thread
From: David Bremner @ 2018-09-08 10:27 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

>
> Would you be happy with me just re-arranging the order, so that the test
> came after?

Also fine.

d

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME
  2018-09-08  9:22     ` David Edmondson
@ 2018-09-08 10:28       ` David Bremner
  0 siblings, 0 replies; 9+ messages in thread
From: David Bremner @ 2018-09-08 10:28 UTC (permalink / raw)
  To: David Edmondson, notmuch

David Edmondson <dme@dme.org> writes:

>
> 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"));
>

OK, that's fair.

d

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-09-08 10:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-25 11:57 [PATCH v1 0/2] Interpret a directory path without a leading slash as relative to $HOME David Edmondson
2018-08-25 11:57 ` [PATCH v1 1/2] test: Absolute and relative directory paths David Edmondson
2018-09-08  0:05   ` David Bremner
2018-09-08  9:22     ` David Edmondson
2018-09-08 10:27       ` David Bremner
2018-08-25 11:57 ` [PATCH v1 2/2] notmuch: Database paths without a leading / are relative to $HOME David Edmondson
2018-09-08  0:10   ` David Bremner
2018-09-08  9:22     ` David Edmondson
2018-09-08 10:28       ` David Bremner

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).