From: Alex Rousskov Date: Thu, 18 Jun 2020 16:30:28 +0000 (+0000) Subject: Avoid corruption of source files when astyle cannot start (#668) X-Git-Tag: SQUID_5_0_4~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f401e3ac0f51c5e0c93a9bcba93ea78cee3409d;p=thirdparty%2Fsquid.git Avoid corruption of source files when astyle cannot start (#668) $ export ASTYLE=/no/such/file $ ./scripts/formater.pl src/tunnel.cc open2: exec of /no/such/file ... failed: No such file or directory # for debugging; most admins will just fix the ASTYLE value $ file src/tunnel.cc src/tunnel.cc: cannot open `src/tunnel.cc' (No such file or ...) $ export ASTYLE=/usr/bin/astyle $ ./scripts/formater.pl src/tunnel.cc Can not open input file: src/tunnel.cc.astylebak.2 $ xxd -C src/tunnel.cc 00000000: 00 Also avoids creation of new source files, as (poorly) illustrated by the single-byte src/tunnel.cc file created (after being removed) above. Also improves diagnostic when dealing with misspelled file names: $ ./scripts/formater.pl src/tunnel.ccsrc/FwdState.cc Can not open input file: src/tunnel.ccsrc/FwdState.cc.astylebak Can't open output file: src/tunnel.ccsrc/FwdState.cc --- diff --git a/scripts/formater.pl b/scripts/formater.pl index 000ea908ac..c04185db3d 100755 --- a/scripts/formater.pl +++ b/scripts/formater.pl @@ -74,6 +74,8 @@ while($out){ next; } + die("Cannot format a non-existent file: $out\n") unless -e $out; + my $in= "$out.astylebak"; my($new_in) = $in; my($i) = 0;