From: Steve Hancock Date: Wed, 9 Dec 2020 13:56:58 +0000 (-0800) Subject: added a uniq filter to avoid processing a file more than once X-Git-Tag: 20210111~47 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=646a5426da23c648e2bc8d294be9ee18aebe90ec;p=perltidy.git added a uniq filter to avoid processing a file more than once --- diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 82633766..f358a081 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -845,6 +845,14 @@ EOM map { [ $_, -e $_ ? -s $_ : 0 ] } @ARGV; } + # Remove duplicate filenames. Otherwise, for example if the user entered + # perltidy -b myfile.pl myfile.pl + # the backup version of the original would be lost. + if ( $number_of_files > 1 ) { + my %seen = (); + @ARGV = grep { !$seen{$_}++ } @ARGV; + } + while ( my $input_file = shift @ARGV ) { my $fileroot; my @input_file_stat; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 2a9e62b2..81d6b333 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,20 @@ =over 4 +=item B + +In the unlikely event that a user enters a filename more than once on the +command line to perltidy, as for 'file1.pl' here + + perltidy file1.pl file1.pl + +then that file will be processed more than once. This looks harmless, but if +the user was also using the -b (backup) parameter, then the original backup +would be overwritten, which is not good. To avoid this, a filter has been +placed on the list of files to remove duplicates. 9 Dec 2020. + +=back + =item B The exit status flag was not being set for the -w option if the -se or if the -q flag