From 278280115c7094f5a117330907de503788e35963 Mon Sep 17 00:00:00 2001 From: espie Date: Sun, 8 May 2022 13:21:04 +0000 Subject: [PATCH] better abstraction: instead of storing a string we're going to parse for signature dates, just annotate the PackageLocation with the info, and decorate the PackingList itself when we finished reading it from the location --- usr.sbin/pkg_add/OpenBSD/Handle.pm | 6 ++--- usr.sbin/pkg_add/OpenBSD/PackageLocation.pm | 11 ++++++--- usr.sbin/pkg_add/OpenBSD/PackageRepository.pm | 7 +++--- .../OpenBSD/PackageRepository/Installed.pm | 23 ++++++++++++++++++- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/usr.sbin/pkg_add/OpenBSD/Handle.pm b/usr.sbin/pkg_add/OpenBSD/Handle.pm index b104a9525cd..12fb2ece71b 100644 --- a/usr.sbin/pkg_add/OpenBSD/Handle.pm +++ b/usr.sbin/pkg_add/OpenBSD/Handle.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Handle.pm,v 1.42 2017/03/07 16:21:28 espie Exp $ +# $OpenBSD: Handle.pm,v 1.43 2022/05/08 13:21:04 espie Exp $ # # Copyright (c) 2007-2009 Marc Espie # @@ -250,9 +250,7 @@ sub get_plist return; } delete $location->{update_info}; - unless ($plist->has('url')) { - OpenBSD::PackingElement::Url->add($plist, $location->url); - } + $location->decorate($plist); if ($plist->localbase ne $state->{localbase}) { $state->say("Localbase mismatch: package has: #1, user wants: #2", $plist->localbase, $state->{localbase}); diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm index 8094bf53c21..cb795f9649a 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageLocation.pm,v 1.58 2022/04/29 10:44:05 espie Exp $ +# $OpenBSD: PackageLocation.pm,v 1.59 2022/05/08 13:21:04 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie # @@ -35,6 +35,12 @@ sub new } +sub decorate +{ + my ($self, $plist) = @_; + $self->{repository}->decorate($plist, $self); +} + sub url { my $self = shift; @@ -136,8 +142,7 @@ sub find_contents while (my $e = $self->next) { if ($e->isFile && is_info_name($e->{name})) { if ($e->{name} eq CONTENTS ) { - my $v = - $self->{extra_content}.$e->contents($extra); + my $v = $e->contents($extra); return $v; } } else { diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm index a5d120bdab7..1ffb6a6ecd1 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageRepository.pm,v 1.171 2019/11/08 14:50:58 espie Exp $ +# $OpenBSD: PackageRepository.pm,v 1.172 2022/05/08 13:21:04 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie # @@ -435,9 +435,9 @@ sub uncompress if ($h) { for my $line (split /\n/, $h->{Comment}) { if ($line =~ m/^key=.*\/(.*)\.sec$/) { - $result .= "\@signer $1\n"; + $object->{signer} = $1; } elsif ($line =~ m/^date=(.*)$/) { - $result .= "\@digital-signature signify2:$1:external\n"; + $object->{signdate} = $1; } } } else { @@ -445,7 +445,6 @@ sub uncompress return undef; } } - $object->{extra_content} = $result; return $fh; } diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm index f33e9c2ba8e..ee7dd0028f6 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Installed.pm,v 1.43 2022/04/29 10:44:05 espie Exp $ +# $OpenBSD: Installed.pm,v 1.44 2022/05/08 13:21:04 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie # @@ -215,6 +215,27 @@ sub reinitialize { } +sub decorate +{ + my ($self, $plist, $location) = @_; + unless ($plist->has('url')) { + OpenBSD::PackingElement::Url->add($plist, $location->url); + } + unless ($plist->has('signer')) { + if (exists $location->{signer}) { + OpenBSD::PackingElement::Signer->add($plist, + $location->{signer}); + } + } + unless ($plist->has('digital-signature')) { + if (exists $location->{signdate}) { + OpenBSD::PackingElement::DigitalSignature->add($plist, + join(':', 'signify2', $location->{signdate}, + 'external')); + } + } +} + package OpenBSD::PackageRepository::Installed; our @ISA = (qw(OpenBSD::PackageRepositoryBase)); -- 2.20.1