Compare commits

..

2 Commits

3 changed files with 149 additions and 144 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).
.PP
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
external bash shell for each port should in theory make \fBprtwash\fP slower
generate its keep list, whereas \fBprtsweep\fP reads the SHA256 or MD5 sums from a manifest.
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
difference is basically undetectable.
.PP

View File

@ -69,7 +69,8 @@ sub parse_args {
print $version."\n";
exit 0;
} 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);
} elsif (-f "$arg") {
print "WARN: $arg is not a port directory or recognized option, ignoring.\n";
@ -96,37 +97,40 @@ sub list_subdirs {
return @list;
}
sub parse_signature {
my @signed = ("Pkgfile",".footprint",".signature","README","README.md",
"pre-install","post-install",".32bit",".nostrip");
sub parse_manifest {
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>) {
if (/^SHA256 \(.+\) =.*$/) {
$_ =~ s/^SHA256 \((.+)\) =.*$/$1/;
push (@signed, $_)
if (($sigtype eq ".signature") and (/^SHA256 \((.+)\) =.*$/)) {
push (@keeplist, $1);
} elsif ($sigtype eq ".md5sum") {
my ($m, $f) = split /\s+/, $_;
push (@keeplist, $f);
}
}
close (FILE);
return @signed ;
return @keeplist ;
}
sub sweep {
my $port = shift;
my $port = shift; my $sigtype = shift;
while ($port =~ s/\/\//\//g) {}
$port =~ s/\/$//;
my @path = split /\//, $port;
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)$';
$builtpkg =~ s/\+/\\\+/; # plus sign in filenames interferes with regex search
opendir (DIR, $port) or return;
foreach my $f (sort(readdir(DIR))) {
next if ( $f eq '.' or $f eq '..' );
$f =~ s/\+/\\\+/;
if ((grep /$f/, @wanted) >= 1 or
if (($wanted{$f}) or
($f =~ /$builtpkg/)*($options{pkgtoo}==0)) {
print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
} else {
@ -149,20 +153,22 @@ sub remove {
}
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.
my $port = shift; my $nf = 0;
if (! -f "$port/.signature") {
if ((! -f "$port/.signature") and (! -f "$port/.md5sum")) {
opendir (PORTDIR,$port) or return;
foreach my $f (readdir PORTDIR) {
next if ($f eq '.' or $f eq '..');
$nf += 1;
}
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);
} elsif (-f "$port/.signature") {
sweep($port,"signature");
} else {
sweep($port);
sweep($port,"md5sum");
}
}

View File

@ -180,17 +180,16 @@ sub do_wash {
print "WARN: no Pkgfile found in $port. Skipping.\n";
return;
} else {
my @keepers = keeplist($port); my $iswanted;
my @keepers = keeplist($port);
my $allbuilds = pop(@keepers);
my $currbuild = pop(@keepers);
my %iswanted = map { $_ => 1 } @keepers;
opendir (DIR,$port) or return;
print "=====> washing $port\n" unless $options{quiet} == 1;
foreach my $f (sort(readdir(DIR))) {
next if ($f eq '.' or $f eq '..');
$f =~ s/\+/\\\+/g; # plus sign in filenames interferes with regex search
$iswanted = ( grep (/$f/, @keepers ) >= 1 );
if ($iswanted or ($options{pkgtoo}==0)*($f =~ /$currbuild/)
if ($iswanted{$f} or ($options{pkgtoo}==0)*($f =~ /$currbuild/)
or ($options{oldver}==0)*($f =~ /$allbuilds/)*($f !~ /$currbuild/)) {
print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
} else {