[PATCH 6/9] search for a reasonable gpg implementation

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Dec 9 19:39:43 PST 2015


When the notmuch database needs to find gpg, have it search reasonable
paths first.
---
 lib/database.cc | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/database.cc b/lib/database.cc
index 62bc6d9..d0e8800 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -2393,6 +2393,17 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
     return status;
 }
 
+static const char*
+_notmuch_database_get_gpg_path (notmuch_database_t *notmuch)
+{
+#define try_gpg_path(z) if (!access(z, X_OK)) return z
+    try_gpg_path("/usr/bin/gpg2");
+    try_gpg_path("/bin/gpg2");
+    try_gpg_path("/usr/bin/gpg");
+    try_gpg_path("/bin/gpg");
+    return NULL;
+}
+
 notmuch_private_status_t
 _notmuch_database_get_crypto_for_protocol (notmuch_database_t *notmuch,
 					   const char *protocol,
@@ -2414,7 +2425,7 @@ _notmuch_database_get_crypto_for_protocol (notmuch_database_t *notmuch,
 	     * here? how would this config get into the library?  Is
 	     * this an option we can set on the database object?  Or
 	     * elsewhere?  */
-	    notmuch->gpg_crypto_ctx = g_mime_gpg_context_new (NULL, "gpg");
+	    notmuch->gpg_crypto_ctx = g_mime_gpg_context_new (NULL, _notmuch_database_get_gpg_path(notmuch));
 	    if (! notmuch->gpg_crypto_ctx)
 		return NOTMUCH_PRIVATE_STATUS_FAILED_CRYPTO_CONTEXT_CREATION;
 
-- 
2.6.2



More information about the notmuch mailing list