[v2,2/2] pactree: Add --gpgdir, set the gpg directory

Message ID 20200107011643.19462-2-develinthedetail@gmail.com
State Accepted, archived
Delegated to: Johannes Löthberg
Headers show
Series [v2,1/2] pactree: Add --debug | expand

Commit Message

Edward E Jan. 7, 2020, 1:16 a.m. UTC
Addresses https://github.com/msys2/MSYS2-packages/issues/1720

Signed-off-by: Edward E <develinthedetail@gmail.com>
---

Anticipating that someone might need to override the default, this
updated patch also adds a --gpgdir option.

Both patches tested on msys2/Win10.

 doc/pactree.8.txt |  4 ++++
 src/Makefile.am   |  4 +++-
 src/pactree.c     | 15 +++++++++++++--
 3 files changed, 20 insertions(+), 3 deletions(-)

Patch

diff --git a/doc/pactree.8.txt b/doc/pactree.8.txt
index 57a91cb..296d04e 100644
--- a/doc/pactree.8.txt
+++ b/doc/pactree.8.txt
@@ -64,6 +64,10 @@  Options
 *\--debug*::
 	Print log messages produced by libalpm.
 
+*\--gpgdir <dir>*::
+	Specify an alternate GnuPG directory for verifying database signatures
+	(default is /etc/pacman.d/gnupg).
+
 
 See Also
 --------
diff --git a/src/Makefile.am b/src/Makefile.am
index 8d33be8..eef0590 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,7 @@  DIST_SUBDIRS = $(SUBDIRS)
 # paths set at make time
 conffile  = ${sysconfdir}/pacman.conf
 dbpath    = ${localstatedir}/lib/pacman/
+gpgdir    = ${sysconfdir}/pacman.d/gnupg/
 
 bin_SCRIPTS = \
 	$(OURSCRIPTS)
@@ -82,7 +83,8 @@  endif
 AM_CPPFLAGS = \
 	-DLOCALEDIR=\"@localedir@\" \
 	-DCONFFILE=\"$(conffile)\" \
-	-DDBPATH=\"$(dbpath)\"
+	-DDBPATH=\"$(dbpath)\" \
+	-DGPGDIR=\"$(gpgdir)\"
 
 AM_CFLAGS = \
 	-pedantic \
diff --git a/src/pactree.c b/src/pactree.c
index feac956..5bc0032 100644
--- a/src/pactree.c
+++ b/src/pactree.c
@@ -106,7 +106,8 @@  static struct color_choices no_color = {
 /* long operations */
 enum {
 	OP_CONFIG = 1000,
-	OP_DEBUG
+	OP_DEBUG,
+	OP_GPGDIR
 };
 
 /* globals */
@@ -125,6 +126,7 @@  static int searchsyncs = 0;
 static int debug = 0;
 static const char *dbpath = DBPATH;
 static const char *configfile = CONFFILE;
+static const char *gpgdir = GPGDIR;
 
 void cb_log(alpm_loglevel_t level, const char *fmt, va_list args)
 {
@@ -253,7 +255,8 @@  static void usage(void)
 			"  -u, --unique         show dependencies with no duplicates (implies -l)\n"
 			"  -v, --version        display the version\n"
 			"      --config <path>  set an alternate configuration file\n"
-			"      --debug          display debug messages\n");
+			"      --debug          display debug messages\n"
+			"      --gpgdir <path>  set an alternate home directory for GnuPG\n");
 }
 
 static void version(void)
@@ -281,6 +284,8 @@  static int parse_options(int argc, char *argv[])
 
 		{"config",  required_argument,    0, OP_CONFIG},
 		{"debug",   no_argument,          0, OP_DEBUG},
+		{"gpgdir",  required_argument,    0, OP_GPGDIR},
+
 		{0, 0, 0, 0}
 	};
 
@@ -301,6 +306,9 @@  static int parse_options(int argc, char *argv[])
 			case OP_DEBUG:
 				debug = 1;
 				break;
+			case OP_GPGDIR:
+				gpgdir = optarg;
+				break;
 			case 'a':
 				style = &graph_default;
 				break;
@@ -539,6 +547,9 @@  int main(int argc, char *argv[])
 		alpm_option_set_logcb(handle, cb_log);
 	}
 
+	/* no need to fail on error here */
+	alpm_option_set_gpgdir(handle, gpgdir);
+
 	if(searchsyncs) {
 		if(register_syncs() != 0) {
 			cleanup(1);