prtsweep.pl: fall back to md5sums if signature file is not found

This commit is contained in:
John McQuah 2023-08-07 08:50:12 -04:00
parent 9ca23cc68d
commit 495ce0457f
2 changed files with 146 additions and 140 deletions

View File

@ -115,8 +115,8 @@ algorithm makes it easy to wash all your locally-curated repositories, in contra
to the algorithm in \fBprtsweep\fP(1) which looks at the sup files used by \fBports\fP(8). to the algorithm in \fBprtsweep\fP(1) which looks at the sup files used by \fBports\fP(8).
.PP .PP
Another contrast between the two tools is that \fBprtwash\fP sources each Pkgfile to Another contrast between the two tools is that \fBprtwash\fP sources each Pkgfile to
generate its keep list, whereas \fBprtsweep\fP reads the signatures file. Spawning an generate its keep list, whereas \fBprtsweep\fP reads the SHA256 or MD5 sums from a manifest.
external bash shell for each port should in theory make \fBprtwash\fP slower Spawning an external bash shell for each port should in theory make \fBprtwash\fP slower
than \fBprtsweep\fP (which does everything in native perl), but on modern hardware the than \fBprtsweep\fP (which does everything in native perl), but on modern hardware the
difference is basically undetectable. difference is basically undetectable.
.PP .PP

View File

@ -69,7 +69,8 @@ sub parse_args {
print $version."\n"; print $version."\n";
exit 0; exit 0;
} elsif ((-d "$arg") || # false for symlink to a portdir, } elsif ((-d "$arg") || # false for symlink to a portdir,
(-f "$arg/.signature")) { # so a second test is needed (-f "$arg/.signature") ||
(-f "$arg/.md5sum")) { # so further tests are needed
push (@portdirs, $arg); push (@portdirs, $arg);
} elsif (-f "$arg") { } elsif (-f "$arg") {
print "WARN: $arg is not a port directory or recognized option, ignoring.\n"; print "WARN: $arg is not a port directory or recognized option, ignoring.\n";
@ -96,37 +97,40 @@ sub list_subdirs {
return @list; return @list;
} }
sub parse_signature { sub parse_manifest {
my @signed = ("Pkgfile",".footprint",".signature","README","README.md",
"pre-install","post-install",".32bit",".nostrip");
my $sigfile = shift; my $sigfile = shift;
open (FILE, $sigfile) or return @signed; my $sigtype = (split /\//, $sigfile)[-1];
my @keeplist = ("Pkgfile",".footprint","README","README.md",
"pre-install","post-install",".32bit",".nostrip");
push (@keeplist,$sigtype);
open (FILE, $sigfile) or return @keeplist;
while (<FILE>) { while (<FILE>) {
if (/^SHA256 \(.+\) =.*$/) { if (($sigtype eq ".signature") and (/^SHA256 \((.+)\) =.*$/)) {
$_ =~ s/^SHA256 \((.+)\) =.*$/$1/; push (@keeplist, $1);
push (@signed, $_) } elsif ($sigtype eq ".md5sum") {
my ($m, $f) = split /\s+/, $_;
push (@keeplist, $f);
} }
} }
close (FILE); close (FILE);
return @signed ; return @keeplist ;
} }
sub sweep { sub sweep {
my $port = shift; my $port = shift; my $sigtype = shift;
while ($port =~ s/\/\//\//g) {} while ($port =~ s/\/\//\//g) {}
$port =~ s/\/$//; $port =~ s/\/$//;
my @path = split /\//, $port; my @path = split /\//, $port;
print "=======> $port\n" unless $options{quiet}==1; print "=======> $port\n" unless $options{quiet}==1;
my @wanted = parse_signature ("$port/.signature"); my %wanted = map { $_ => 1 } parse_manifest ("$port/.$sigtype");
my $builtpkg=$path[-1].'#.*pkg\.tar\.(bz2|gz|lz|xz)$'; my $builtpkg=$path[-1].'#.*pkg\.tar\.(bz2|gz|lz|xz)$';
$builtpkg =~ s/\+/\\\+/; # plus sign in filenames interferes with regex search $builtpkg =~ s/\+/\\\+/; # plus sign in filenames interferes with regex search
opendir (DIR, $port) or return; opendir (DIR, $port) or return;
foreach my $f (sort(readdir(DIR))) { foreach my $f (sort(readdir(DIR))) {
next if ( $f eq '.' or $f eq '..' ); next if ( $f eq '.' or $f eq '..' );
$f =~ s/\+/\\\+/; if (($wanted{$f}) or
if ((grep /$f/, @wanted) >= 1 or
($f =~ /$builtpkg/)*($options{pkgtoo}==0)) { ($f =~ /$builtpkg/)*($options{pkgtoo}==0)) {
print "... keeping file $port/$f.\n" unless $options{quiet} == 1; print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
} else { } else {
@ -149,20 +153,22 @@ sub remove {
} }
sub do_sweep { sub do_sweep {
# argument either a real directory (not symlink) or has a signature; # argument either a real directory (not symlink) or has a manifest;
# this subroutine determines which condition was satisfied. # this subroutine determines which condition was satisfied.
my $port = shift; my $nf = 0; my $port = shift; my $nf = 0;
if (! -f "$port/.signature") { if ((! -f "$port/.signature") and (! -f "$port/.md5sum")) {
opendir (PORTDIR,$port) or return; opendir (PORTDIR,$port) or return;
foreach my $f (readdir PORTDIR) { foreach my $f (readdir PORTDIR) {
next if ($f eq '.' or $f eq '..'); next if ($f eq '.' or $f eq '..');
$nf += 1; $nf += 1;
} }
closedir (PORTDIR); closedir (PORTDIR);
print "WARN: $port/.signature not found, invalid port directory."; print "WARN: no signature or md5sum found in directory $port, skipping.\n";
rm_emptydir($port,$nf); rm_emptydir($port,$nf);
} elsif (-f "$port/.signature") {
sweep($port,"signature");
} else { } else {
sweep($port); sweep($port,"md5sum");
} }
} }