From a75d3d3949fd3f8ff7c84906be6a13eebef1ec0e Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 11 Jul 2022 06:59:28 -0700 Subject: [PATCH] update comments and docs --- CHANGES.md | 14 ++++++++++++++ bin/perltidy | 5 +++++ lib/Perl/Tidy.pm | 12 +++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b6f32d13..b14107f3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,20 @@ ## 2022 06 13.01 + - Fix for issue git #103. For parameter -b, or --backup-and-modify-in-place, + the default backup method has been changed to preserve the inode value + of the file being formatted. If this causes a problem, the previous + method is available and can be used by setting -backup-mode='move', or + -bm='move'. The new default corresponds to -bm='copy'. The difference + between the two methods is as follows. For the older method, + -bm='move', the input file was moved to the backup, and a new file was + created for the formatted output. This caused the inode to change. For + the new default method, -bm='copy', the input is copied to the backup + and then the input file is reopened and rewritten. This preserves the + file inode. Before using the --backup-and-modify-in-place + parameter please verify that it works correctly in your environment and + operating system. + - Fix undefined value message when perltidy -D is used (git #104) - Added parameter --delete-repeated-commas (-drc) to delete repeated diff --git a/bin/perltidy b/bin/perltidy index 40b3a967..d7c57b58 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -243,6 +243,11 @@ extension F<.bak>. Any existing F<.bak> file will be deleted. See next item for changing the default backup extension, and for eliminating the backup file altogether. +B: Writing back to the input file increases the risk of data loss +or corruption in the event of a software or hardware malfunction. Before using +the B<-b> parameter please be sure to have backups and verify that it works +correctly in your environment and operating system. + A B<-b> flag will be ignored if input is from standard input or goes to standard output, or if the B<-html> flag is set. diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index d908a9b6..b49abd29 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1159,11 +1159,9 @@ sub backup_method_copy { $self->set_output_file_permissions( $backup_file, \@input_file_stat, $in_place_modify ); - # Open a file with the original input file name for writing ... Opening - # with either ">" or "+>" should truncate the existing data. The '+>' - # indicates that we may also read, even though there will be nothing left - # to read, which might help insure that we get the same inode. - open( my $fout, "+>", $input_file ) + # Open the original input file for writing ... opening with ">" will + # truncate the existing data. + open( my $fout, ">", $input_file ) || Die( "problem re-opening $input_file for write for -b option; check file and directory permissions: $ERRNO\n" ); @@ -1206,8 +1204,8 @@ EOM or Die("cannot close '$input_file' with -b option: $OS_ERROR\n"); # Set permissions of the output file to match the input file. This is - # necessary even if the inode remains unchanged. In particular, - # the suid/sgid bits may have changed. + # necessary even if the inode remains unchanged because suid/sgid bits may + # have been reset. $self->set_output_file_permissions( $input_file, \@input_file_stat, $in_place_modify ); -- 2.39.5