[lxc-devel] [distrobuilder/master] shared: Use RunCommandWithFds for GPG

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Jul 22 15:02:45 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 388 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190722/e2c8baf5/attachment.bin>
-------------- next part --------------
From 6e89f0854c01a32f095df52cf1808eaeed9f01b8 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 22 Jul 2019 16:58:14 +0200
Subject: [PATCH] shared: Use RunCommandWithFds for GPG

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/util.go | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/shared/util.go b/shared/util.go
index 8db7f65..fe31fc4 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -152,7 +152,9 @@ func recvGPGKeys(gpgDir string, keyserver string, keys []string) (bool, error) {
 
 	args = append(args, append([]string{"--recv-keys"}, fingerprints...)...)
 
-	out, err := lxd.TryRunCommand("gpg", args...)
+	var out bytes.Buffer
+
+	err := RunCommandWithFds(nil, &out, &out, "gpg", args...)
 	if err != nil {
 		return false, err
 	}
@@ -160,7 +162,7 @@ func recvGPGKeys(gpgDir string, keyserver string, keys []string) (bool, error) {
 	// Verify output
 	var importedKeys []string
 	var missingKeys []string
-	lines := strings.Split(out, "\n")
+	lines := strings.Split(out.String(), "\n")
 
 	for _, l := range lines {
 		if strings.HasPrefix(l, "gpg: key ") && (strings.HasSuffix(l, " imported") || strings.HasSuffix(l, " not changed")) {
@@ -356,3 +358,21 @@ func SetEnvVariables(env Environment) Environment {
 
 	return oldEnv
 }
+
+func RunCommandWithFds(stdin io.Reader, stdout io.Writer, stderr io.Writer, name string, arg ...string) error {
+	cmd := exec.Command(name, arg...)
+
+	if stdin != nil {
+		cmd.Stdin = stdin
+	}
+
+	if stdout != nil {
+		cmd.Stdout = stdout
+	}
+
+	if stderr != nil {
+		cmd.Stderr = stderr
+	}
+
+	return cmd.Run()
+}


More information about the lxc-devel mailing list