prtsweep.pl: improved handling of @ARGV when using shell globs
This commit is contained in:
parent
9ccc1ebf59
commit
954afb830f
@ -7,10 +7,7 @@
|
|||||||
# This is a script for removing rubbish from a CRUX port tree.
|
# This is a script for removing rubbish from a CRUX port tree.
|
||||||
# Distributed under the terms of the GPL license.
|
# Distributed under the terms of the GPL license.
|
||||||
#
|
#
|
||||||
# Partial Changelog:
|
# ChangeLog and author information available in the prt-utils tarball.
|
||||||
# 1.2.1 - First rewrite in perl
|
|
||||||
# 1.2 - Added support for renamed sources
|
|
||||||
# 1.1.3 - Replace .md5sum with .signature in the KEEP_FILES list
|
|
||||||
#
|
#
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
@ -39,6 +36,7 @@ EOT
|
|||||||
|
|
||||||
sub parse_args {
|
sub parse_args {
|
||||||
foreach my $arg (@ARGV) {
|
foreach my $arg (@ARGV) {
|
||||||
|
next if (-f $arg); # no filenames, only options or directories
|
||||||
if ($arg =~ /^-a$/) {
|
if ($arg =~ /^-a$/) {
|
||||||
$options{auto} = 1;
|
$options{auto} = 1;
|
||||||
} elsif ($arg =~ /^-d$/) {
|
} elsif ($arg =~ /^-d$/) {
|
||||||
@ -69,7 +67,7 @@ sub list_subdirs {
|
|||||||
|
|
||||||
opendir(DIR, $path) or return;
|
opendir(DIR, $path) or return;
|
||||||
foreach my $entry(sort(readdir(DIR))) {
|
foreach my $entry(sort(readdir(DIR))) {
|
||||||
next if ( substr($entry,0,1) eq "." );
|
next if ( substr($entry,0,1) eq '.' );
|
||||||
push (@list, "$path/$entry") if -d "$path/$entry";
|
push (@list, "$path/$entry") if -d "$path/$entry";
|
||||||
}
|
}
|
||||||
closedir(DIR);
|
closedir(DIR);
|
||||||
@ -91,17 +89,6 @@ sub parse_signature {
|
|||||||
return @signed ;
|
return @signed ;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rm_emptydir {
|
|
||||||
my $port = shift; my $nf = shift;
|
|
||||||
my $msg = ($options{rmdir}==1) ? "\n":
|
|
||||||
" use -d to remove empty directories.\n";
|
|
||||||
my $modal = ($options{dryrun}==1) ? "would be" : "";
|
|
||||||
$msg = ($nf == 0) ? "$msg $port: empty directory $modal deleted.\n" :
|
|
||||||
"$msg cannot remove $port: directory not empty\n";
|
|
||||||
print $msg;
|
|
||||||
rmdir ($port) if (($nf == 0) and ($options{dryrun} == 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
sub sweep {
|
sub sweep {
|
||||||
my $port = shift;
|
my $port = shift;
|
||||||
while ($port =~ s/\/\//\//g) {}
|
while ($port =~ s/\/\//\//g) {}
|
||||||
@ -116,32 +103,26 @@ sub sweep {
|
|||||||
|
|
||||||
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/\+/\\\+/; # plus sign in filenames interferes with regex search
|
$f =~ s/\+/\\\+/; # plus sign in filenames interferes with regex search
|
||||||
if ((grep /$f/, @wanted) >= 1 or ($f =~ /$builtpkg/)) {
|
if ((grep /$f/, @wanted) >= 1 or ($f =~ /$builtpkg/)) {
|
||||||
print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
|
print "... keeping file $port/$f.\n" unless $options{quiet} == 1;
|
||||||
} else {
|
} else {
|
||||||
my $ft=remove_notify("$port/$f");
|
remove ("$port/$f");
|
||||||
remove_forreal("$port/$f", $ft) if $options{dryrun} == 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir (DIR);
|
closedir (DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub remove_notify {
|
sub remove {
|
||||||
my $path=shift;
|
my $path=shift;
|
||||||
my $type = (-d $path) ? "directory" : "file";
|
|
||||||
my $append = ($options{dryrun}==1) ? "(dry run)\n" : "\n";
|
my $append = ($options{dryrun}==1) ? "(dry run)\n" : "\n";
|
||||||
print "+ removing $type $path $append";
|
if (-d $path) {
|
||||||
return $type;
|
print "+ removing directory $path $append";
|
||||||
}
|
rmtree ($path,0,1) if ($options{dryrun}==0);
|
||||||
|
|
||||||
sub remove_forreal {
|
|
||||||
my $path = shift; my $type = shift;
|
|
||||||
if ($type eq "file") {
|
|
||||||
unlink "$path" or return;
|
|
||||||
} else {
|
} else {
|
||||||
rmtree ($path,0,1);
|
print "+ removing file $path $append";
|
||||||
|
if ($options{dryrun}==0) { unlink "$path" or return; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +142,17 @@ sub do_sweep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub rm_emptydir {
|
||||||
|
my $port = shift; my $nf = shift;
|
||||||
|
my $msg = ($options{rmdir}==1) ? "\n":
|
||||||
|
" use -d to remove empty directories.\n";
|
||||||
|
my $modal = ($options{dryrun}==0) ? "" : "would be";
|
||||||
|
$msg = ($nf == 0) ? "$msg empty directory $port $modal deleted.\n" :
|
||||||
|
"$msg cannot remove $port: directory not empty\n";
|
||||||
|
print $msg;
|
||||||
|
rmdir ($port) if (($nf == 0) and ($options{dryrun} == 0));
|
||||||
|
}
|
||||||
|
|
||||||
sub getportdirs {
|
sub getportdirs {
|
||||||
my $collection;
|
my $collection;
|
||||||
my @basedirs;
|
my @basedirs;
|
||||||
|
Loading…
Reference in New Issue
Block a user