We disabled the checksum check because it was rather expensive, but actually
we also store timestamps in packing-lists

This is a first draft at a better check. What this does:
- compare the fs timestamp with the packing-list timestamp. This should be
very cheap in most cases, since we're already inthe directory ready 
to delete the file.

- IF the timestamp doesn't match, we go run the checksum before deleting the
file.

There might be some fringe cases I haven't seen, so see this more as a POC
than a finished diff, but I'm curious if there are still many packages 
that diddle their installed bits after install.

feedback welcome.


Index: OpenBSD/Delete.pm
===================================================================
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/Delete.pm,v
retrieving revision 1.160
diff -u -p -r1.160 Delete.pm
--- OpenBSD/Delete.pm   24 Jul 2019 18:05:26 -0000      1.160
+++ OpenBSD/Delete.pm   30 Oct 2021 15:57:38 -0000
@@ -432,7 +432,21 @@ sub is_intact
                $state->log("Couldn't delete #1 (no checksum)", $realname);
                return 0;
        }
-       return 1 unless $state->defines('checksum');
+       my $force_checksum = 0;
+       if (defined $self->{ts}) {
+               my @s = stat $realname;
+               if (@s == 0) {
+                       $state->say("Couldn't stat #1", $realname);
+                       return 0;
+               }
+               if ($s[9] != $self->{ts}) {
+                       $force_checksum = 1;
+                       $state->say("Found possibly modified file #1", 
$realname);
+               }
+       }
+       if (!$force_checksum) {
+               return 1 unless $state->defines('checksum');
+       }
        my $d = $self->compute_digest($realname, $self->{d});
        return 1 if $d->equals($self->{d});
        if ($self->fullname eq $realname) {

Reply via email to