Skip to content

Commit

Permalink
lib/portage/gpg.py: use temporary gpg out file instead of /dev/null
Browse files Browse the repository at this point in the history
GnuPG removes the --output file on failure. Removing /dev/null breaks all kinds
of things. So lets use a temporary file for the output instead.

If the file already exists then we remove it to prevent GnuPG from complaining
about the file already existing and asking us if we want to choose a different
--output file.

Closes: https://bugs.gentoo.org/912808
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
  • Loading branch information
AndrewAmmerlaan committed Aug 23, 2023
1 parent 104d649 commit e10f193
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/portage/gpg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2001-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

import os
import subprocess
import sys
import threading
Expand All @@ -22,6 +23,7 @@ def __init__(self, settings):
"""
Portage settings are needed to run GPG unlock command.
"""
self.GPG_tmp_file="/tmp/portage_gpg_output"
self.settings = settings
self.thread = None
self.GPG_signing_base_command = self.settings.get(
Expand All @@ -35,7 +37,7 @@ def __init__(self, settings):
f"--homedir {self.signing_gpg_home} "
f"--digest-algo {self.digest_algo} "
f"--local-user {self.signing_gpg_key} "
"--output /dev/null /dev/null",
f"--output {self.GPG_tmp_file} /dev/null",
)

if "gpg-keepalive" in self.settings.features:
Expand All @@ -60,6 +62,11 @@ def unlock(self):
# GPG does not need to ask password, so can be ignored.
writemsg(f"{colorize('WARN', str(e))}\n")

try:
os.remove(self.GPG_tmp_file)
except FileNotFoundError:
pass

cmd = shlex_split(varexpand(self.GPG_unlock_command, mydict=self.settings))
return_code = subprocess.Popen(cmd).wait()

Expand Down

0 comments on commit e10f193

Please sign in to comment.