This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=0d366f052da26b99fdc72c71dae8500ccfd833d5 commit 0d366f052da26b99fdc72c71dae8500ccfd833d5 Author: Guillem Jover <guil...@debian.org> AuthorDate: Sun Feb 9 00:15:09 2025 +0100 Dpkg::OpenPGP::Backend::GnuPG: Refactor newline workaround into a function Turn the logic and its effects into a function so that then we can later on conditionally call it only when necessary. --- scripts/Dpkg/OpenPGP/Backend/GnuPG.pm | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/Dpkg/OpenPGP/Backend/GnuPG.pm b/scripts/Dpkg/OpenPGP/Backend/GnuPG.pm index c930cb351..39cc1f068 100644 --- a/scripts/Dpkg/OpenPGP/Backend/GnuPG.pm +++ b/scripts/Dpkg/OpenPGP/Backend/GnuPG.pm @@ -175,22 +175,34 @@ sub verify { return $self->_gpg_verify($data, $sig, undef, @certs); } -sub inline_sign { - my ($self, $data, $inlinesigned, $key) = @_; - - return OPENPGP_MISSING_CMD if ! $self->has_backend_cmd(); +sub _gpg_fixup_newline { + my $origfile = shift; - my $file = basename($data); my $signdir = File::Temp->newdir('dpkg-sign.XXXXXXXX', TMPDIR => 1); - my $signfile = "$signdir/$file"; + my $signfile = $signdir . q(/) . basename($origfile); + + copy($origfile, $signfile); # Make sure the file to sign ends with a newline, as GnuPG does not adhere # to the OpenPGP specification (see <https://dev.gnupg.org/T7106>). - copy($data, $signfile); open my $signfh, '>>', $signfile or syserr(g_('cannot open %s'), $signfile); print { $signfh } "\n"; - close $signfh or syserr(g_('cannot close %s'), $signfile); + close $signfh + or syserr(g_('cannot close %s'), $signfile); + + # Return the dir object so that it is kept in scope in the caller, and + # thus not cleaned up within this function. + return ($signdir, $signfile); +} + +sub inline_sign { + my ($self, $data, $inlinesigned, $key) = @_; + + return OPENPGP_MISSING_CMD if ! $self->has_backend_cmd(); + + my ($signdir, $signfile); + ($signdir, $signfile) = _gpg_fixup_newline($data); my @exec = ($self->{cmd}); push @exec, _gpg_options_weak_digests(); -- Dpkg.Org's dpkg