A bit McGyverish, since the tools we have usually deal with actual packages,
so OpenBSD::Search is out of the question.

This makes register-plist error out if it finds a newer packing-list with
the exact same pkgpath in the PLIST_DB.

So, if you use PLIST_DB (by default), it will notice if you break things
by having version numbers go backwards, instead of only checking that in
dependencies.

In case you end up with bogus packing-list, you have all the information
to remove it anyways (directory + pkgname).

diff --git a/bin/register-plist b/bin/register-plist
index 4ba8db9..2c0d282 100644
--- a/bin/register-plist
+++ b/bin/register-plist
@@ -442,6 +442,36 @@ sub compare_lists
        return act_on_compare($r, $p1, $p2, $result, $state);
 }
 
+sub compare_versions
+{
+       my ($dir, $plist, $state) = @_;
+
+       opendir (my $dirhandle, $dir) or return 0;
+       my (@parsed) = OpenBSD::PackageName::splitname($plist->pkgname);
+       $parsed[1] = '*';
+       my $reference = join('-', @parsed);
+       my $n = OpenBSD::PackageName->from_string($plist->pkgname);
+       my $result = 0;
+       while (my $d = readdir $dirhandle) {
+               next if $d eq '.' or $d eq '..';
+               my (@cmp) = OpenBSD::PackageName::splitname($d);
+               $cmp[1] = '*';
+               next if  join('-', @cmp) ne $reference;
+
+               my $p2 = OpenBSD::PackingList->fromfile("$dir/$d",
+                       \&OpenBSD::PackingList::ExtraInfoOnly);
+               next if $p2->fullpkgpath ne $plist->fullpkgpath;
+               my $n2 = OpenBSD::PackageName->from_string($p2->pkgname);
+               my $c = $n->compare($n2);
+               if ($c < 0) {
+                       $state->errsay("Found newer package #1 in #2",
+                           $p2->pkgname, $dir);
+                       $result = 1;
+               }
+       }
+       return $result;
+}
+
 my $state = OpenBSD::State->new('register-plist');
 $state->handle_options('tp', '[-t p1 p2] dir pkg ...');
 if (@ARGV < 2 && !$state->opt('p')) {
@@ -507,6 +537,7 @@ for my $pkgfile (@ARGV) {
                            $state);
                        last;
                }
+               $error += compare_versions($dir, $plist, $state);
        }
        if (!$error) {
                my $result = $dirs[0].'/'.$plist->pkgname;

Reply via email to