summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2017-03-09 15:36:15 +0000
committerMarc Espie <espie@cvs.openbsd.org>2017-03-09 15:36:15 +0000
commitb8450ce308afc9cdc0e0f48464be1e86257cbd4b (patch)
tree50d0fb730376ff00b1893a123f3857793ecf1032
parent4d37d1aaded8720cb9289c296a9ca845bd000f2d (diff)
take the checksum part out of line.
Fix the "no checksum" part: pass thru do_not_delete, and do it even if quick is set. Simplify the error messages in case realname and fullname are identical (which is the most common case)
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm52
1 files changed, 32 insertions, 20 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
index af94e56ed4d..817e8c324de 100644
--- a/usr.sbin/pkg_add/OpenBSD/Delete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Delete.pm,v 1.146 2016/08/27 18:17:46 espie Exp $
+# $OpenBSD: Delete.pm,v 1.147 2017/03/09 15:36:14 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -398,6 +398,33 @@ sub prepare_for_deletion
}
}
+sub is_intact
+{
+ my ($self, $state, $realname) = @_;
+ return 1 if defined($self->{link}) or $self->{nochecksum};
+ if (!defined $self->{d}) {
+ if ($self->fullname eq $realname) {
+ $state->say("NOT deleting #1 (no checksum)", $realname);
+ } else {
+ $state->say("Not deleting #1 (no checksum for #2",
+ $realname, $self->fullname);
+ }
+ $state->log("Couldn't delete #1 (no checksum)", $realname);
+ return 0;
+ }
+ return 1 if $self->{quick};
+ my $d = $self->compute_digest($realname, $self->{d});
+ return 1 if $d->equals($self->{d});
+ if ($self->fullname eq $realname) {
+ $state->say("NOT deleting #1 (bad checksum)", $realname);
+ } else {
+ $state->say("Not deleting #1 (bad checksum for #2)",
+ $realname, $self->fullname);
+ }
+ $state->log("Couldn't delete #1 (bad checksum)", $realname);
+ return 0;
+}
+
sub delete
{
my ($self, $state) = @_;
@@ -422,28 +449,13 @@ sub delete
$state->say("Unexpected symlink: #1", $realname);
$self->do_not_delete($state);
} else {
- if (! -f $realname) {
+ if (!-f $realname) {
$state->say("File #1 does not exist", $realname);
return;
}
- unless (defined($self->{link}) or $self->{nochecksum} or $state->{quick}) {
- if (!defined $self->{d}) {
- $state->say("Problem: #1 does not have a checksum\n".
- "NOT deleting: #2",
- $self->fullname, $realname);
- $state->log("Couldn't delete #1 (no checksum)", $realname);
- return;
- }
- my $d = $self->compute_digest($realname,
- $self->{d});
- if (!$d->equals($self->{d})) {
- $state->say("Problem: checksum doesn't match for #1\n".
- "NOT deleting: #2",
- $self->fullname, $realname);
- $state->log("Couldn't delete #1 (bad checksum)", $realname);
- $self->do_not_delete($state);
- return;
- }
+ if (!$self->is_intact($state, $realname)) {
+ $self->do_not_delete($state);
+ return;
}
}
}