]> git.donarmstrong.com Git - perltidy.git/commitdiff
added a uniq filter to avoid processing a file more than once
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 9 Dec 2020 13:56:58 +0000 (05:56 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 9 Dec 2020 13:56:58 +0000 (05:56 -0800)
lib/Perl/Tidy.pm
local-docs/BugLog.pod

index 826337668a3ca57132bb778e98e01a57a053c6ff..f358a0818b3a7780b4405d88688a258c1406d1e1 100644 (file)
@@ -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;
index 2a9e62b26046ebaa5a046a0d100de67306004a30..81d6b3333be096b172b007216e7fa19eaf2959d9 100644 (file)
@@ -2,6 +2,20 @@
 
 =over 4
 
+=item B<Avoid processing a file more than once>
+
+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<Fix for issue git #49, exit status not correctly set>
 
 The exit status flag was not being set for the -w option if the -se or if the -q flag