[Gpa-commits] r893 - trunk/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 8 18:47:50 CEST 2008


Author: werner
Date: 2008-05-08 18:47:48 +0200 (Thu, 08 May 2008)
New Revision: 893

Modified:
   trunk/src/ChangeLog
   trunk/src/gpa.c
   trunk/src/gpgmetools.c
   trunk/src/gpgmetools.h
Log:
Properly switch to gpg2.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-05-08 13:11:15 UTC (rev 892)
+++ trunk/src/ChangeLog	2008-05-08 16:47:48 UTC (rev 893)
@@ -1,3 +1,8 @@
+2008-05-08  Werner Koch  <wk at g10code.com>
+
+	* gpgmetools.c (gpa_switch_to_gpg2): New.
+	* gpa.c (main): Use it.
+
 2008-05-08  Marcus Brinkmann  <marcus at g10code.de>
 
 	* filesigndlg.c (gpa_file_sign_dialog_set_force_sig_mode): Forcing

Modified: trunk/src/gpa.c
===================================================================
--- trunk/src/gpa.c	2008-05-08 13:11:15 UTC (rev 892)
+++ trunk/src/gpa.c	2008-05-08 16:47:48 UTC (rev 893)
@@ -361,14 +361,8 @@
   }
 #endif
 
-  /* Prefer gpg2 over gpg1.  Fixme: We need to test whether gpg2 is
-     actually properly installed.  */
-  if (!access ("/usr/local/bin/gpg2", X_OK))
-    gpgme_set_engine_info (GPGME_PROTOCOL_OpenPGP, 
-                           "/usr/local/bin/gpg2", NULL);
-  else if (!access ("/usr/bin/gpg2", X_OK))
-    gpgme_set_engine_info (GPGME_PROTOCOL_OpenPGP, 
-                           "/usr/bin/gpg2", NULL);
+  /* Prefer gpg2 over gpg1.  */
+  gpa_switch_to_gpg2 ();
 
 
   /* Handle command line options.  */

Modified: trunk/src/gpgmetools.c
===================================================================
--- trunk/src/gpgmetools.c	2008-05-08 13:11:15 UTC (rev 892)
+++ trunk/src/gpgmetools.c	2008-05-08 16:47:48 UTC (rev 893)
@@ -1155,7 +1155,49 @@
   return 0;
 }
 
+/* Try switching to the gpg2 backend.  */
+void
+gpa_switch_to_gpg2 (void)
+{
+  const char *oldname;
+  char *newname;
+  char *p;
 
+  if (is_gpg_version_at_least ("2.0.0"))
+    return; /* Already using 2.0.  */
+
+  oldname = get_gpg_path ();
+  g_return_if_fail (oldname && *oldname);
+  newname = xmalloc (strlen (oldname) + 1 + 1);
+  strcpy (newname, oldname);
+#if G_OS_WIN32
+# define OLD_NAME "gpg.exe"  
+# define NEW_NAME "gpg2.exe"  
+  for (p=newname; *p; p++)
+    if (*p == '\\')
+      *p = '/';
+#else
+# define OLD_NAME "gpg"  
+# define NEW_NAME "gpg2"  
+#endif /*G_OS_WIN32*/
+  p = strrchr (newname, '/');
+  if (p)
+    p++;
+  if (!strcmp (p, OLD_NAME))
+    {
+      strcpy (p, NEW_NAME);
+      if (!access (newname, X_OK))
+        {
+          gpgme_set_engine_info (GPGME_PROTOCOL_OpenPGP, newname, NULL);
+          g_message ("switched engine to `%s'", newname);
+        }
+    }
+#undef OLD_NAME
+#undef NEW_NAME
+  xfree (newname);
+}
+
+
 /* Return 1 if the gpg engine has at least version NEED_VERSION,
    otherwise 0.  */
 int

Modified: trunk/src/gpgmetools.h
===================================================================
--- trunk/src/gpgmetools.h	2008-05-08 13:11:15 UTC (rev 892)
+++ trunk/src/gpgmetools.h	2008-05-08 16:47:48 UTC (rev 893)
@@ -188,6 +188,9 @@
 /* Release all keys in the array KEYS as weel as ARRY itself.  */
 void gpa_gpgme_release_keyarray (gpgme_key_t *keys);
 
+/* Try switching to the gpg2 backend.  */
+void gpa_switch_to_gpg2 (void);
+
 /* Return true if the gpg engine has at least version NEED_VERSION.  */
 int is_gpg_version_at_least (const char *need_version);
 



More information about the Gpa-commits mailing list