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

classic Classic list List threaded Threaded
4 messages Options
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

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

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

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v2 2/2] test: Absolute and relative directory paths.

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

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

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

In reply to this post by David Edmondson
On Sat, Sep 08 2018, David Edmondson wrote:

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

Series LGTM. Looked previous discussion, thought about using /etc/passwd
but $HOME is more flexible. Did not test, though...


Tomi

> ---
>  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
>
> _______________________________________________
> notmuch mailing list
> [hidden email]
> https://notmuchmail.org/mailman/listinfo/notmuch
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

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

Tomi Ollila <[hidden email]> writes:

> On Sat, Sep 08 2018, David Edmondson wrote:
>
>> 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.
>
> Series LGTM. Looked previous discussion, thought about using /etc/passwd
> but $HOME is more flexible. Did not test, though...
>

Series pushed to master.

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch