From: Otto Moerbeek Date: Tue, 26 Nov 2019 14:39:05 +0000 (+0100) Subject: More robust script X-Git-Tag: auth-4.3.0-alpha1~26^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a4e056a36a3e98a86fc74fe734327c526e92ce7;p=thirdparty%2Fpdns.git More robust script --- diff --git a/build-scripts/format-code b/build-scripts/format-code index 6a4d6d10f5..e3398bd2ea 100755 --- a/build-scripts/format-code +++ b/build-scripts/format-code @@ -2,28 +2,39 @@ # # Reformat code, but do not touch if no changes. -# Report if a files was changed. # -if [ "$0" != "./build-scripts/format-code" ]; then +if [ "$0" != "./build-scripts/format-code" -a "$0" != "build-scripts/format-code" ]; then echo "Please run me from the root checkout dir" exit 1 fi +if [ $# = 0 ]; then + echo usage: $0 file... + echo + echo format C++ files, does not touch non-regular files + exit 0 +fi if [ ! -e .clang-format ]; then echo "No .clang-format file found in ."; exit 1 fi for file in "${@}"; do - if ! clang-format -style=file "$file" > "$file.xxx"; then - rm "$file.xxx" + if [ -h "$file" -o ! -f "$file" ]; then + echo "$file: skipped, not a regular file or unreadable" + continue + fi + tmp=$(mktemp $file.XXXXXXXX) + if ! clang-format -style=file "$file" > "$tmp"; then + rm "$tmp" else - if ! cmp -s "$file" "$file.xxx"; then - echo "$file reformatted" - mv "$file.xxx" "$file" + if ! cmp -s "$file" "$tmp"; then + echo "$file: reformatted" + mv "$tmp" "$file" else - rm "$file.xxx" + echo "$file: already formatted to perfection" + rm "$tmp" fi fi done