Remove postfix if/for (PBP)

This commit is contained in:
Dan Church 2023-07-20 13:05:12 -05:00
parent 15c466e581
commit 98c2c04263
Signed by: h3xx
GPG key ID: EA2BF379CD2CDBD0
4 changed files with 43 additions and 28 deletions

View file

@ -36,7 +36,9 @@ sub add {
$self->{_entries}->{$hash} = [];
}
push @{$self->{_entries}->{$hash}}, $file;
$callback->($file) if ref $callback eq 'CODE';
if (ref $callback eq 'CODE') {
$callback->($file);
}
}
$self->{_files_in_hash}->{$file->{name}} = 1;
}

View file

@ -30,7 +30,9 @@ sub hr_size {
}
# default to ($sz, 'bytes')
@ret = ($sz, $sizes[0]) unless @ret;
unless (@ret) {
@ret = ($sz, $sizes[0]);
}
return wantarray ? @ret : "@ret";
}

View file

@ -143,8 +143,9 @@ MAIN: {
my @dirs_to_process = map { Cwd::abs_path($_) } (@ARGV ? @ARGV : ($ENV{PWD}));
my @files;
print STDERR 'Finding files...'
if $verbose;
if ($verbose) {
print STDERR 'Finding files...';
}
find(sub {
# outright skip directories (don't report skip)
@ -158,9 +159,10 @@ MAIN: {
push @files, Directory::Simplify::File->new($File::Find::name);
}, @dirs_to_process);
printf STDERR "%d files found",
scalar @files
if $verbose;
if ($verbose) {
printf STDERR '%d files found',
scalar @files;
}
# Limit to or exclude file patterns specified by `-m' or `-M', respectively
#
@ -175,20 +177,18 @@ MAIN: {
@files = grep {
$_->{rel_name} =~ $files_match
} @files;
if ($file_ct_before_filter != scalar @files) {
printf STDERR " (%d files filtered by -m rule)",
$file_ct_before_filter - scalar @files
if $verbose;
if ($verbose && $file_ct_before_filter != scalar @files) {
printf STDERR ' (%d files filtered by -m rule)',
$file_ct_before_filter - scalar @files;
}
if (length $files_exclude) {
$file_ct_before_filter = scalar @files;
@files = grep {
not $_->{rel_name} =~ $files_exclude
} @files;
if ($file_ct_before_filter != scalar @files) {
printf STDERR " (%d files filtered by -M rule)",
$file_ct_before_filter - scalar @files
if $verbose;
if ($verbose && $file_ct_before_filter != scalar @files) {
printf STDERR ' (%d files filtered by -M rule)',
$file_ct_before_filter - scalar @files;
}
}
@ -196,21 +196,26 @@ MAIN: {
# unique size. The reasoning being that file sizes do not match, there's no
# possible way those two files can have the same contents.
my %file_sizes;
++$file_sizes{$_->{size}} foreach @files;
foreach my $file (@files) {
++$file_sizes{$file->{size}};
}
@files = grep {
$file_sizes{$_->{size}} > 1
} @files;
printf STDERR " (%d candidates).\n",
scalar @files
if $verbose;
if ($verbose) {
printf STDERR " (%d candidates).\n",
scalar @files;
}
unless (@files) {
printf STDERR "Nothing to do.\n";
exit 0;
}
print STDERR "Generating hashes..." if $verbose;
if ($verbose) {
print STDERR 'Generating hashes...';
}
my $filehash = Directory::Simplify::FileHash->new;
my $report_every = 1; # seconds
my $processed_bytes = 0;
@ -234,8 +239,9 @@ MAIN: {
files => \@files,
callback => $cb,
);
print STDERR "done.\n"
if $verbose;
if ($verbose) {
print STDERR "done.\n";
}
my $generator = Directory::Simplify::Instruction::Generator->new(
filehash => $filehash,
@ -245,14 +251,17 @@ MAIN: {
my $freed_bytes = 0;
foreach my $inst ($generator->instructions) {
print STDERR $inst, "\n" if $verbose;
if ($verbose) {
print STDERR $inst, "\n";
}
$inst->run;
$freed_bytes += $inst->bytes_freed;
}
printf STDERR "freed %s bytes (%0.4G %s)\n",
Directory::Simplify::Utils::addcommas($freed_bytes),
Directory::Simplify::Utils::hr_size($freed_bytes)
if $print_freed or $verbose;
if ($print_freed or $verbose) {
printf STDERR "freed %s bytes (%0.4G %s)\n",
Directory::Simplify::Utils::addcommas($freed_bytes),
Directory::Simplify::Utils::hr_size($freed_bytes);
}
}

View file

@ -116,7 +116,9 @@ sub run_script_capture {
print STDERR "+ @cmd\n";
my $pid = open3 $in, '>&CATCHOUT', '>&CATCHERR', @cmd;
waitpid $pid, 0;
seek $_, 0, 0 for \*CATCHOUT, \*CATCHERR;
foreach my $handle (\*CATCHOUT, \*CATCHERR) {
seek $handle, 0, 0;
}
return (
$?,