summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2016-08-09 13:40:28 -0500
committerAdam J. Stewart <ajstewart426@gmail.com>2016-08-11 09:56:41 -0500
commit87d0a7c3156070316ca28f356ef97c8208236fab (patch)
tree17ff41907e166077e509dba8356a00ff1a7b69aa
parent09c9786fab620f161e7be1dd2813b3d320724ebd (diff)
downloadspack-87d0a7c3156070316ca28f356ef97c8208236fab.tar.gz
spack-87d0a7c3156070316ca28f356ef97c8208236fab.tar.bz2
spack-87d0a7c3156070316ca28f356ef97c8208236fab.tar.xz
spack-87d0a7c3156070316ca28f356ef97c8208236fab.zip
Always clean up tmp files, even if killed
-rwxr-xr-xshare/spack/qa/run-flake824
1 files changed, 14 insertions, 10 deletions
diff --git a/share/spack/qa/run-flake8 b/share/spack/qa/run-flake8
index 2b758b7051..e41cd0d471 100755
--- a/share/spack/qa/run-flake8
+++ b/share/spack/qa/run-flake8
@@ -25,6 +25,18 @@ changed+=($(git diff --name-only --find-renames -- '*.py'))
# Ensure that each file in the array is unique
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.
for file in "${changed[@]}"; do
# 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
done
-return_code=0
if [[ "${changed[@]}" ]]; then
echo =======================================================
echo flake8: running flake8 code checks on spack.
@@ -64,17 +75,10 @@ if [[ "${changed[@]}" ]]; then
echo "Flake8 checks were clean."
else
echo "Flake8 found errors."
- return_code=1
+ exit 1
fi
else
echo No core framework files modified.
fi
-# Restore original package files after modifying them.
-for file in "${changed[@]}"; do
- if [[ -e "${file}.sbak~" ]]; then
- mv "${file}.sbak~" "${file}"
- fi
-done
-
-exit $return_code
+exit 0