From ab93feac61a84a66166fdb6c17012050d5ce964c Mon Sep 17 00:00:00 2001 From: espie Date: Wed, 13 Apr 2022 21:22:40 +0000 Subject: [PATCH] scaffolding from using the locate db that's now in quirks to avoid asking the network about updateinfo (not active yet, you need to uncomment some lines) --- usr.sbin/pkg_add/OpenBSD/PackageLocation.pm | 42 ++++++++++++++++++++- usr.sbin/pkg_add/OpenBSD/PkgAdd.pm | 12 +++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocation.pm index 2c443279214..b527382f3c4 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.53 2019/07/10 11:13:06 espie Exp $ +# $OpenBSD: PackageLocation.pm,v 1.54 2022/04/13 21:22:40 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie # @@ -23,6 +23,7 @@ package OpenBSD::PackageLocation; use OpenBSD::PackageInfo; use OpenBSD::Temp; use OpenBSD::Error; +use OpenBSD::Paths; sub new { @@ -59,6 +60,10 @@ OpenBSD::Auto::cache(update_info, if ($self->name =~ /^quirks\-/) { return $self->plist; } +# if (-f OpenBSD::Paths->updateinfodb) { +# my $info = $self->get_update_info_fromdb; +# return $info if defined $info; +# } return $self->plist(\&OpenBSD::PackingList::UpdateInfoOnly, sub { return 0 if $_[0] =~ m/^\@option\s+always-update\b/m; @@ -67,6 +72,41 @@ OpenBSD::Auto::cache(update_info, }); }); +my $db_location = ""; + +sub set_db_location +{ + my ($class, $location) = @_; + + $db_location = $location->{repository}->url; +} + +sub get_update_info_fromdb +{ + my $self = shift; + if ($self->{repository}->url ne $db_location) { + return; + } + open my $fh, "-|", OpenBSD::Paths->locate, + '-d', OpenBSD::Paths->updateinfodb, $self->name.":*"; + my $content = ''; + while (<$fh>) { + if (m/\@option\s+always-update/) { + return undef; + } + if (m/^.*?\:(.*)/) { + $content .= $1."\n"; + } else { + return undef; + } + } + close ($fh); + if ($content eq '') { + return undef; + } + open my $fh2, "<", \$content; + return OpenBSD::PackingList->read($fh2); +} # make sure self is opened and move to the right location if need be. sub _opened diff --git a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm index 8e0222e269f..a9c17f7b48c 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgAdd.pm,v 1.125 2022/04/06 14:15:27 espie Exp $ +# $OpenBSD: PkgAdd.pm,v 1.126 2022/04/13 21:22:40 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie # @@ -328,7 +328,7 @@ sub display_timestamp sub find_kept_handle { - my ($set, $n, $state) = @_; + my ($set, $n, $state) = @_; unless (defined $n->{location} && defined $n->{location}{update_info}) { $n->complete($state); } @@ -358,6 +358,11 @@ sub find_kept_handle } } $set->check_security($state, $plist, $o); + if ($set->{quirks}) { + # The installed package has inst: for a location, we want + # the newer one (which is identical) + OpenBSD::PackageLocation->set_db_location($n->location); + } $set->move_kept($o); $o->{tweaked} = OpenBSD::Add::tweak_package_status($pkgname, $state); @@ -853,6 +858,9 @@ sub really_add add_installed($pkgname); delete $handle->{partial}; OpenBSD::PkgCfl::register($handle, $state); + if ($set->{quirks}) { + OpenBSD::PackageLocation->set_db_location($handle->location); + } } delete $state->{partial}; $set->{solver}->register_dependencies($state); -- 2.20.1