Always clean up tmp files, even if killed

This commit is contained in:
Adam J. Stewart 2016-08-09 13:40:28 -05:00
parent 09c9786fab
commit 87d0a7c315

View File

@ -25,6 +25,18 @@ changed+=($(git diff --name-only --find-renames -- '*.py'))
# Ensure that each file in the array is unique # Ensure that each file in the array is unique
changed=($(printf '%s\n' "${changed[@]}" | sort -u)) changed=($(printf '%s\n' "${changed[@]}" | sort -u))
function cleanup {
# Restore original package files after modifying them.
for file in "${changed[@]}"; do
if [[ -e "${file}.sbak~" ]]; then
mv "${file}.sbak~" "${file}"
fi
done
}
# Cleanup temporary files upon exit or when script is killed
trap cleanup EXIT SIGINT SIGTERM
# Add approved style exemptions to the changed packages. # Add approved style exemptions to the changed packages.
for file in "${changed[@]}"; do for file in "${changed[@]}"; do
# Make a backup to restore later # Make a backup to restore later
@ -52,7 +64,6 @@ for file in "${changed[@]}"; do
perl -i -pe 's/^(.*(https?|file)\:.*)$/\1 # NOQA: ignore=E501/' $file perl -i -pe 's/^(.*(https?|file)\:.*)$/\1 # NOQA: ignore=E501/' $file
done done
return_code=0
if [[ "${changed[@]}" ]]; then if [[ "${changed[@]}" ]]; then
echo ======================================================= echo =======================================================
echo flake8: running flake8 code checks on spack. echo flake8: running flake8 code checks on spack.
@ -64,17 +75,10 @@ if [[ "${changed[@]}" ]]; then
echo "Flake8 checks were clean." echo "Flake8 checks were clean."
else else
echo "Flake8 found errors." echo "Flake8 found errors."
return_code=1 exit 1
fi fi
else else
echo No core framework files modified. echo No core framework files modified.
fi fi
# Restore original package files after modifying them. exit 0
for file in "${changed[@]}"; do
if [[ -e "${file}.sbak~" ]]; then
mv "${file}.sbak~" "${file}"
fi
done
exit $return_code