mirror of
				https://codeberg.org/h3xx/simplify_static_dir
				synced 2024-08-14 23:57:24 +00:00 
			
		
		
		
	Remove postfix if/for (PBP)
This commit is contained in:
		
							parent
							
								
									15c466e581
								
							
						
					
					
						commit
						98c2c04263
					
				
					 4 changed files with 43 additions and 28 deletions
				
			
		|  | @ -36,7 +36,9 @@ sub add { | ||||||
|                 $self->{_entries}->{$hash} = []; |                 $self->{_entries}->{$hash} = []; | ||||||
|             } |             } | ||||||
|             push @{$self->{_entries}->{$hash}}, $file; |             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; |         $self->{_files_in_hash}->{$file->{name}} = 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -30,7 +30,9 @@ sub hr_size { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     # default to ($sz, 'bytes') |     # default to ($sz, 'bytes') | ||||||
|     @ret = ($sz, $sizes[0]) unless @ret; |     unless (@ret) { | ||||||
|  |         @ret = ($sz, $sizes[0]); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return wantarray ? @ret : "@ret"; |     return wantarray ? @ret : "@ret"; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -143,8 +143,9 @@ MAIN: { | ||||||
|     my @dirs_to_process = map { Cwd::abs_path($_) } (@ARGV ? @ARGV : ($ENV{PWD})); |     my @dirs_to_process = map { Cwd::abs_path($_) } (@ARGV ? @ARGV : ($ENV{PWD})); | ||||||
| 
 | 
 | ||||||
|     my @files; |     my @files; | ||||||
|     print STDERR 'Finding files...' |     if ($verbose) { | ||||||
|         if $verbose; |         print STDERR 'Finding files...'; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     find(sub { |     find(sub { | ||||||
|         # outright skip directories (don't report skip) |         # outright skip directories (don't report skip) | ||||||
|  | @ -158,9 +159,10 @@ MAIN: { | ||||||
|         push @files, Directory::Simplify::File->new($File::Find::name); |         push @files, Directory::Simplify::File->new($File::Find::name); | ||||||
|     }, @dirs_to_process); |     }, @dirs_to_process); | ||||||
| 
 | 
 | ||||||
|     printf STDERR "%d files found", |     if ($verbose) { | ||||||
|         scalar @files |         printf STDERR '%d files found', | ||||||
|         if $verbose; |             scalar @files; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     # Limit to or exclude file patterns specified by `-m' or `-M', respectively |     # Limit to or exclude file patterns specified by `-m' or `-M', respectively | ||||||
|     # |     # | ||||||
|  | @ -175,20 +177,18 @@ MAIN: { | ||||||
|     @files = grep { |     @files = grep { | ||||||
|         $_->{rel_name} =~ $files_match |         $_->{rel_name} =~ $files_match | ||||||
|     } @files; |     } @files; | ||||||
|     if ($file_ct_before_filter != scalar @files) { |     if ($verbose && $file_ct_before_filter != scalar @files) { | ||||||
|         printf STDERR " (%d files filtered by -m rule)", |         printf STDERR ' (%d files filtered by -m rule)', | ||||||
|             $file_ct_before_filter - scalar @files |             $file_ct_before_filter - scalar @files; | ||||||
|             if $verbose; |  | ||||||
|     } |     } | ||||||
|     if (length $files_exclude) { |     if (length $files_exclude) { | ||||||
|         $file_ct_before_filter = scalar @files; |         $file_ct_before_filter = scalar @files; | ||||||
|         @files = grep { |         @files = grep { | ||||||
|             not $_->{rel_name} =~ $files_exclude |             not $_->{rel_name} =~ $files_exclude | ||||||
|         } @files; |         } @files; | ||||||
|         if ($file_ct_before_filter != scalar @files) { |         if ($verbose && $file_ct_before_filter != scalar @files) { | ||||||
|             printf STDERR " (%d files filtered by -M rule)", |             printf STDERR ' (%d files filtered by -M rule)', | ||||||
|                 $file_ct_before_filter - scalar @files |                 $file_ct_before_filter - scalar @files; | ||||||
|                 if $verbose; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -196,21 +196,26 @@ MAIN: { | ||||||
|     # unique size. The reasoning being that file sizes do not match, there's no |     # unique size. The reasoning being that file sizes do not match, there's no | ||||||
|     # possible way those two files can have the same contents. |     # possible way those two files can have the same contents. | ||||||
|     my %file_sizes; |     my %file_sizes; | ||||||
|     ++$file_sizes{$_->{size}} foreach @files; |     foreach my $file (@files) { | ||||||
|  |         ++$file_sizes{$file->{size}}; | ||||||
|  |     } | ||||||
|     @files = grep { |     @files = grep { | ||||||
|         $file_sizes{$_->{size}} > 1 |         $file_sizes{$_->{size}} > 1 | ||||||
|     } @files; |     } @files; | ||||||
| 
 | 
 | ||||||
|     printf STDERR " (%d candidates).\n", |     if ($verbose) { | ||||||
|         scalar @files |         printf STDERR " (%d candidates).\n", | ||||||
|         if $verbose; |             scalar @files; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     unless (@files) { |     unless (@files) { | ||||||
|         printf STDERR "Nothing to do.\n"; |         printf STDERR "Nothing to do.\n"; | ||||||
|         exit 0; |         exit 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     print STDERR "Generating hashes..." if $verbose; |     if ($verbose) { | ||||||
|  |         print STDERR 'Generating hashes...'; | ||||||
|  |     } | ||||||
|     my $filehash = Directory::Simplify::FileHash->new; |     my $filehash = Directory::Simplify::FileHash->new; | ||||||
|     my $report_every = 1; # seconds |     my $report_every = 1; # seconds | ||||||
|     my $processed_bytes = 0; |     my $processed_bytes = 0; | ||||||
|  | @ -234,8 +239,9 @@ MAIN: { | ||||||
|         files => \@files, |         files => \@files, | ||||||
|         callback => $cb, |         callback => $cb, | ||||||
|     ); |     ); | ||||||
|     print STDERR "done.\n" |     if ($verbose) { | ||||||
|         if $verbose; |         print STDERR "done.\n"; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     my $generator = Directory::Simplify::Instruction::Generator->new( |     my $generator = Directory::Simplify::Instruction::Generator->new( | ||||||
|         filehash => $filehash, |         filehash => $filehash, | ||||||
|  | @ -245,14 +251,17 @@ MAIN: { | ||||||
|     my $freed_bytes = 0; |     my $freed_bytes = 0; | ||||||
| 
 | 
 | ||||||
|     foreach my $inst ($generator->instructions) { |     foreach my $inst ($generator->instructions) { | ||||||
|         print STDERR $inst, "\n" if $verbose; |         if ($verbose) { | ||||||
|  |             print STDERR $inst, "\n"; | ||||||
|  |         } | ||||||
|         $inst->run; |         $inst->run; | ||||||
|         $freed_bytes += $inst->bytes_freed; |         $freed_bytes += $inst->bytes_freed; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     printf STDERR "freed %s bytes (%0.4G %s)\n", |     if ($print_freed or $verbose) { | ||||||
|         Directory::Simplify::Utils::addcommas($freed_bytes), |         printf STDERR "freed %s bytes (%0.4G %s)\n", | ||||||
|         Directory::Simplify::Utils::hr_size($freed_bytes) |             Directory::Simplify::Utils::addcommas($freed_bytes), | ||||||
|             if $print_freed or $verbose; |             Directory::Simplify::Utils::hr_size($freed_bytes); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -116,7 +116,9 @@ sub run_script_capture { | ||||||
|     print STDERR "+ @cmd\n"; |     print STDERR "+ @cmd\n"; | ||||||
|     my $pid = open3 $in, '>&CATCHOUT', '>&CATCHERR', @cmd; |     my $pid = open3 $in, '>&CATCHOUT', '>&CATCHERR', @cmd; | ||||||
|     waitpid $pid, 0; |     waitpid $pid, 0; | ||||||
|     seek $_, 0, 0 for \*CATCHOUT, \*CATCHERR; |     foreach my $handle (\*CATCHOUT, \*CATCHERR) { | ||||||
|  |         seek $handle, 0, 0; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return ( |     return ( | ||||||
|         $?, |         $?, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue