prt-auf: add sync command

This commit is contained in:
John McQuah 2023-11-29 01:10:28 +00:00
parent 56a8fc12d4
commit c749f5c595

View File

@ -41,13 +41,13 @@ my @basedirs = @{$bldirs[0]}; my @localports = @{$bldirs[1]};
get_locked_and_aliased();
if (($action !~ /^(fsearch|isinst|current)$/) and ($osearch{cache}==0)) {
if (($action !~ /^(fsearch|isinst|current|sync)$/) and ($osearch{cache}==0)) {
@allports = list_ports();
fill_hashes_from_pkgfiles();
}
if ($osearch{cache}==1) { fill_hashes_from_cache(); }
if ($action !~ /^(search|dsearch|fsearch|info|dup|ls|readme|cat)$/) {
if ($action !~ /^(search|dsearch|fsearch|info|dup|ls|readme|cat|sync)$/) {
open (DB, "$altroot$pkgdb") or die "Could not open package database!\n";
local $/="";
while (<DB>) { $V_INST{$1} = $2 if m/^(.*)\n(.*)\n/; }
@ -75,6 +75,7 @@ if ($action eq "path") { @results = find_port_by_name($query[0],1,1,0);
} elsif ($action eq "install") { @results = up_inst(@query);
} elsif ($action eq "dup") { $ind=find_dups(@query);
} elsif ($action eq "remove") { $ind=uninstall(@query);
} elsif ($action eq "sync") { sync(@query);
} elsif ($action =~ /^(isinst|current|sysup)$/) { ($ind, @results) = port_diff($1,@query);
} elsif ($action =~ /(.*)diff$/) { ($ind, @results) = port_diff($1);
} elsif ($action =~ /^list(.*)/) { @results = list_ports($1);
@ -202,7 +203,7 @@ while (my $arg = shift) {
} elsif ($arg =~ /^(lock|unlock|listlocked|current|isinst)$/) { $action = $1;
} elsif ($arg =~ /^(diff|quickdiff|printf|listinst|listorphans)$/) {
$action = $1; $odepends{tree} = 0;
} elsif ($arg =~ /^(depends|quickdep|dup|dependent)$/) { $action = $1;
} elsif ($arg =~ /^(depends|quickdep|dup|dependent|sync)$/) { $action = $1;
} elsif ($arg eq "deptree") { $action = $arg; $odepends{tree} = 1;
} elsif ($arg =~ /^(readme|cat|edit|ls|help|version|cache)$/) { $action = $1;
} elsif ($arg eq "--tree") { $odepends{tree} = 1;
@ -297,6 +298,33 @@ while (<PORTS>) { chomp;
return \@basedirs, \@localports;
}
sub sync {
my $sup_path = "/etc/ports";
my @OPT_COLLECTIONS=@_; my @drivers;
opendir(my $drv, "$sup_path/drivers") or return;
foreach my $d (sort(readdir($drv))) {
next if ($d =~ /^\./) or (! -x "$sup_path/drivers/$d");
push @drivers, $d;
}
closedir($drv);
if ($#OPT_COLLECTIONS >= 0) { # Update selected collections
foreach my $coll (@OPT_COLLECTIONS) {
if (! glob("$sup_path/$coll.*")) {
print("$coll not configured in $sup_path!\n"); next;
}
foreach my $suffix (@drivers) {
system("$sup_path/drivers/$suffix","$sup_path/$coll.$suffix") if (-f "$sup_path/$coll.$suffix");
}
}
} else { # Update all collections
foreach my $driver (@drivers) {
while (my $active = glob("$sup_path/*.$driver")) {
system("$sup_path/drivers/$driver",$active);
}
}
}
}
sub find_dups {
my %seen; my $format=shift; my @dupinfo; my @info1; my $dupstr; my @hits;
foreach my $pp (@allports) { my $pn = (split /\//, $pp)[-1]; $seen{$pn}++; }