prt-auf: fixed the lookup key used when accessing the %opkg hash

This commit is contained in:
John McQuah 2022-06-13 03:50:42 -04:00
parent 730ab19a6a
commit 8dac60ee7b

View File

@ -23,7 +23,7 @@ my %opkg = ( margs => "", aargs => "", rargs => "", runscripts => "yes",
makecommand => "/usr/bin/pkgmk", addcommand => "/usr/bin/pkgadd",
removecommand => "/usr/bin/pkgrm", test => "no" );
my @bldirs = parse_prt_conf();
my $prtconf = "/etc/prt-get.conf"; my @bldirs = parse_prt_conf($prtconf);
my @basedirs = @{$bldirs[0]}; my @localports = @{$bldirs[1]};
################### Process the given command #########################
@ -51,7 +51,7 @@ if ($action =~ /^(diff|quickdiff|listlocked|depends|deptree|remove|install|updat
if ($action eq "path") { @results = find_port_by_name(@query,1,1,0);
} elsif ($action eq "search") { @results = find_port_by_name(@query,0,$osearch{path},1);
} elsif ($action eq "fsearch") { $hh = find_port_by_file(".footprint", $query[-1]);
} elsif ($action eq "fsearch") { $hh = find_port_by_file(".footprint", @query);
} elsif ($action eq "dsearch") { @results = find_port_by_desc(@query);
} elsif ($action eq "info") { $portpath = find_port_by_name(@query,1,1,0);
@results = get_pkgfile_fields($portpath,"all") if ($portpath);
@ -61,7 +61,7 @@ if ($action eq "path") { @results = find_port_by_name(@query,1,1,0);
printf_ports($query[0],@results);
} elsif ($action eq "lock") { port_lock(@query);
} elsif ($action eq "unlock") { port_unlock(@query);
} elsif ($action eq "ls") { port_ls($query[0]);
} elsif ($action eq "ls") { port_ls(@query);
} elsif ($action =~ /^(cat|edit|readme)$/) { port_edit($1,@query);
} elsif ($action =~ /^(depends|deptree|quickdep)$/) { @results=deporder($1,@query);
} elsif ($action eq "dependent") { @results=list_ports("dependent",@query);
@ -100,7 +100,7 @@ if (($action =~ /^(listinst|listorphans)/)
printf $strf, "Found in", "Matching File";
foreach my $fh (keys %hits) {
chomp($hits{$fh});
printf $strf, $fh, (split /\s/, $hits{$fh})[-1];
printf $strf, $fh, (split /\s/, $hits{$fh})[2];
}
} elsif ($action =~ /^(diff|quickdiff|current|isinst|dup)$/) {
exit $ind;
@ -206,12 +206,17 @@ sub parse_args {
}
if (($#query > 0) and
($action =~ /^(search|dsearch|fsearch|info|readme|path|ls)$/)) {
print "warning: $1 takes only one argument; ignoring all but the last.\n";
print "warning: $1 takes only one argument; ignoring all but the first.\n";
}
if ((! @query) and
($action =~ /^(search|dsearch|fsearch|info|readme|path|ls)$/)) {
print "$1 requires an argument.\n"; exit 1;
}
if (($action =~ /^(search|dsearch|fsearch)$/) and ($osearch{regex}==0)) {
$query[0] =~ s/\+/\\\+/g; # plus signs in the pattern must be escaped,
$query[0] =~ s/\./\\\./g; # since the user did not request 'regex'.
$query[0] =~ s/\//\\\//g; # same goes for slash and period.
}
if (($#query != 0) and
($action =~ /^(deptree|dependent)$/)) {
print "$1 requires exactly one argument.\n"; exit 1;
@ -224,7 +229,7 @@ sub parse_args {
}
sub parse_prt_conf {
my @basedirs; my @localports; my $conf = "/etc/prt-get.conf";
my @basedirs; my @localports; my $conf = shift;
open(PORTS, $conf) or die "could not open $conf";
while (<PORTS>) { chomp;
@ -282,7 +287,6 @@ sub find_dups {
}
sub get_locked_and_aliased {
local $/ = "\n";
if (-f $prtalias) {
open (AL, $prtalias);
while (<AL>) { $ALIASES{$1} = $2 if m/^\s*(.*)\s*:\s*(.*)/; }
@ -313,7 +317,7 @@ sub printf_ports {
print CACHE "V5\n";
foreach my $pp (@targets) {
$p = (split /\//, $pp)[-1];
@pstats = (get_pkgfile_fields($pp,"all"));
@pstats = get_pkgfile_fields($pp,"all");
printf CACHE "%s\n"x($#pstats+1), @pstats;
printf CACHE "\n";
} close (CACHE);
@ -337,7 +341,7 @@ sub printf_ports {
sub fill_hashes_from_cache {
open (my $cf,$prtcache) or die "cannot use $prtcache as a cache!\n";
local $/="\n"; my $p; my $deps;
my $p; my $deps;
my $ignored=<$cf>; # first line only contains the cache format version
while (1) {
@ -398,8 +402,6 @@ sub get_pkgfile_fields {
sub find_port_by_file { # for now only used to search footprints, but can be generalized
my $portfile = shift; my $query = shift; my ($lp, $candidate, $fh); my %hits=();
$query =~ s/\+/\\\+/g unless ($osearch{regex}==1);
$query =~ s/\./\\\./g unless ($osearch{regex}==1);
my $linewanted = qr/$query/is;
LOCALENTRY: foreach $lp (@localports) {
open ($fh, "$lp/$portfile") or die "cannot open $portfile for $lp\n";
@ -425,16 +427,12 @@ sub find_port_by_file { # for now only used to search footprints, but can be gen
sub find_port_by_desc {
my $query=shift;
$query =~ s/\+/\\\+/g unless ($osearch{regex}==1);
$query =~ s/\./\\\./g unless ($osearch{regex}==1);
my @hits = grep { $DESC{$_} =~ /$query/i } keys %DESC;
return @hits;
}
sub find_port_by_name {
my $query = shift; my $exact=shift; my $fullpath=shift; my $exhaustive=shift;
$query =~ s/\+/\\\+/g unless ($osearch{regex}==1);
$query =~ s/\./\\\./g unless ($osearch{regex}==1);
my $pattern = ($exact==1) ? qr/^$query$/s : qr/$query/is;
my %names_only = map { ($_ => (split /\//, $_)[-1]) } @allports;
my @hits = grep { $names_only{$_} =~ $pattern } @allports;
@ -498,11 +496,6 @@ sub list_ports {
} elsif ($subset eq "locked") { @found=@LOCKED;
} elsif ($subset =~ /^(orphans|dependent)$/) {
my $seed=shift;
if ( ((! $seed) and ($subset eq "dependent")) or
((shift @_) and ($subset eq "dependent")) ) {
print "dependent requires exactly one argument.\n";
return;
}
if (($subset eq "dependent") and (! find_port_by_name($seed,1,1,0))) {
print "$seed not found in the ports tree.\n"; return;
}
@ -650,12 +643,10 @@ sub up_inst { # returns scalar references to five arrays;
my $PKGMK=$opkg{makecommand}; my $PKGADD=$opkg{addcommand};
my $SUDO="/usr/bin/doas"; my $FAKEROOT="/usr/bin/fakeroot";
# prepend commands with sudo/doas/fakeroot if the effective user id is not root
$SUDO = (-x $SUDO) ? $SUDO : "/usr/bin/sudo";
$FAKEROOT = (-x $FAKEROOT) ? $FAKEROOT : $SUDO;
# prepend commands with sudo/doas/fakeroot if the effective user id is not root
if ($> != 0) { $PKGADD = "$SUDO $PKGADD"; }
# $PKGMK = "$FAKEROOT $PKGMK"; }
if ($> != 0) { $PKGADD = "$SUDO $PKGADD"; $PKGMK = "$FAKEROOT $PKGMK"; }
# resolve all dependencies unless the command was 'grpinst'
my @targets=($type eq "grpinst") ? @_ : deporder("quickdep",@_);
@ -666,9 +657,9 @@ sub up_inst { # returns scalar references to five arrays;
# exempt any locked ports from an sysup operation
%EXEMPT = map { $_ => 1 } @LOCKED;
%WANTED = map { $_ => 1 } @requested;
if ($action eq "sysup") { @targets = grep {! $EXEMPT{$_}} @targets;
if ($action eq "sysup") { @targets = grep {! defined $EXEMPT{$_}} @targets;
} else {
@targets = grep {(! $EXEMPT{$_}) or ($WANTED{$_})} @targets;
@targets = grep {(! defined $EXEMPT{$_}) or ($WANTED{$_})} @targets;
}
# first determine the directories from which pkgmk must be called
@ -690,7 +681,7 @@ sub up_inst { # returns scalar references to five arrays;
$mkcmd{$t} = "echo \"skipped build ($t provided by an alias)\"";
} else {
$mkcmd{$t} = "" if ((port_diff("utd",$t)==0) and ($opkg{margs} !~ /-f/));
$mkcmd{$t} = "" if (($type eq "install") and ($V_INST{$t}) and ($opkg{margs} !~ /-f/));
$mkcmd{$t} = "" if (($type eq "install") and ($V_INST{$t}) and ($opkg{$t} !~ /-f/));
$mkcmd{$t} = "echo \"skipped build ($t up to date)\"" if ((-f $builtpkg{$t}) and
((-M $builtpkg{$t}) < (-M "$pdirs{$t}/Pkgfile")));
}
@ -715,7 +706,6 @@ sub up_inst { # returns scalar references to five arrays;
$status{$t} .= ( $?>>8 == 0 ) ? "post-install ok. " : "post-install failed. ";
}
}
last if (($status{$t} =~ /failed/) and ($type eq "grpinst"));
}
@ -737,7 +727,7 @@ sub sysup {
}
sub find_built_pkg {
my $target = shift; my $CONF="/etc/pkgmk.conf"; local $/="\n";
my $target = shift; my $CONF="/etc/pkgmk.conf";
my $COMPRESSION; my $PKG_DIR; my $portpath = (find_port_by_name($target,1,1,0));
my ($version, $release) = (get_pkgfile_fields($portpath))[0,1];