1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# ex:ts=8 sw=4:
# $OpenBSD: Update.pm,v 1.95 2009/11/16 15:01:30 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
use strict;
use warnings;
package OpenBSD::Update;
use OpenBSD::Interactive;
use OpenBSD::PackageInfo;
use OpenBSD::PackageLocator;
use OpenBSD::PackageName;
use OpenBSD::Error;
use OpenBSD::UpdateSet;
sub new
{
my $class = shift;
return bless {}, $class;
}
sub add_updateset
{
my ($self, $set, $handle, $location) = @_;
my $n = OpenBSD::Handle->from_location($location);
$handle->{done} = $n;
$set->add_newer($n);
}
sub process_handle
{
my ($self, $set, $h, $state) = @_;
my $pkgname = $h->pkgname;
if (defined $h->{update}) {
$state->say("Update to $pkgname already found");
return 0;
}
if ($pkgname =~ m/^(?:\.libs\d*|partial)\-/o) {
$state->say("Not updating $pkgname, remember to clean it");
return 0;
}
my @search = ();
push(@search, OpenBSD::Search::Stem->split($pkgname));
my $found;
my $plist;
if (!$state->{defines}->{downgrade}) {
push(@search, OpenBSD::Search::FilterLocation->more_recent_than($pkgname));
}
push(@search, OpenBSD::Search::FilterLocation->new(
sub {
my $l = shift;
if (@$l == 0) {
return $l;
}
if (@$l == 1 && $state->{defines}->{pkgpath}) {
return $l;
}
my @l2 = ();
$plist = OpenBSD::PackingList->from_installation($pkgname, \&OpenBSD::PackingList::UpdateInfoOnly);
if (!defined $plist) {
Fatal("Can't locate $pkgname");
}
for my $handle (@$l) {
$handle->set_arch($state->{arch});
if (!$handle) {
next;
}
my $p2 = $handle->update_info;
if (!$p2) {
next;
}
if ($p2->has('arch')) {
unless ($p2->{arch}->check($state->{arch})) {
next;
}
}
if ($plist->signature eq $p2->signature) {
$found = $handle;
push(@l2, $handle);
next;
}
if ($plist->match_pkgpath($p2)) {
push(@l2, $handle);
}
}
return \@l2;
}));
if (!$state->{defines}->{allversions}) {
push(@search, OpenBSD::Search::FilterLocation->keep_most_recent);
}
my $l = OpenBSD::PackageLocator->match_locations(@search);
if (@$l == 0) {
return undef;
}
if (@$l == 1) {
if ($state->{defines}->{pkgpath}) {
$state->say("Directly updating $pkgname -> ", $l->[0]->name);
$self->add_updateset($set, $h, $l->[0]);
return 1;
}
if (defined $found && $found eq $l->[0] &&
!$plist->uses_old_libs && !$state->{defines}->{installed}) {
my $msg = "No need to update $pkgname";
$state->progress->message($msg);
$state->say($msg) if $state->{beverbose};
return 0;
}
}
$state->say("Candidates for updating $pkgname -> ",
join(' ', map {$_->name} @$l));
my $r = $state->choose_location($pkgname, $l);
if (defined $r) {
$self->add_updateset($set, $h, $r);
return 1;
} else {
$state->{issues} = 1;
return undef;
}
}
sub process_hint
{
my ($self, $set, $hint, $state) = @_;
my $l;
my $hint_name = $hint->pkgname;
my $k = OpenBSD::Search::FilterLocation->keep_most_recent;
# first try to find us exactly
$state->progress->message("Looking for $hint");
$l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Exact->new($hint_name), $k);
if (@$l == 0) {
my $t = $hint_name;
$t =~ s/\-\d([^-]*)\-?/--/;
$l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Stem->new($t), $k);
}
my $r = $state->choose_location($hint_name, $l);
if (defined $r) {
$self->add_updateset($set, $hint, $r);
return 1;
} else {
return 0;
}
}
sub process_set
{
my ($self, $set, $state) = @_;
my $problem;
my $need_update;
for my $h ($set->older) {
next if $h->{done};
my $r = $self->process_handle($set, $h, $state);
if (!defined $r) {
$problem = 1;
}
if ($r) {
$need_update = 1;
}
}
for my $h ($set->hints) {
next if $h->{done};
my $r = $self->process_hint($set, $h, $state);
if (!defined $r) {
$problem = 1;
}
if ($r) {
$need_update = 1;
}
}
if ($problem) {
$state->tracker->mark_cantupdate($set);
return 0;
} elsif (!$need_update) {
$state->tracker->mark_uptoupdate($set);
return 0;
}
return 1;
}
1;
|