Skip to content
This repository has been archived by the owner on Jun 6, 2020. It is now read-only.

Commit

Permalink
Added proper cleanup trap
Browse files Browse the repository at this point in the history
  • Loading branch information
G. Roggemans committed Jun 11, 2016
1 parent 1efb8a8 commit 5b3275a
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/compiler.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ compiler.cleanup() {
rm "$target"
fi
}
trap compiler.cleanup EXIT SIGINT SIGTERM

##############################################################################

Expand Down Expand Up @@ -88,7 +89,6 @@ compiler.compile() {
cp "$target" "$dest"
if [ ! "$?" -eq 0 ]; then
log.fail "Could not write $dest"
compiler.cleanup
exit 1
fi

Expand Down Expand Up @@ -120,7 +120,6 @@ compiler.parse_file() {
local ret="$?"
if [ "$ret" -eq 1 -o "$ret" -eq 2 ]; then
compiler.print_error "'if' without matching 'fi'"
compiler.cleanup
exit 1
fi
done < "$file"
Expand Down Expand Up @@ -176,7 +175,6 @@ compiler.parse_if() {

# Only reached if no FI was encountered
compiler.print_error "'if' without matching 'fi'"
compiler.cleanup
exit 1
}

Expand All @@ -199,7 +197,6 @@ compiler.parse_line() {
compiler.parse_file "$file"
else
compiler.print_error "File not found : '$line'"
compiler.cleanup
exit 1
fi
;;
Expand All @@ -209,7 +206,6 @@ compiler.parse_line() {
compiler.parse_file "$file" "raw"
else
compiler.print_error "File not found : '$line'"
compiler.cleanup
exit 1
fi
;;
Expand Down Expand Up @@ -247,13 +243,11 @@ compiler.parse_line() {
msg.print "$file_name: $line"
;;
fail)
msg.print "$line"
compiler.cleanup
log.warn "Failed to compile: $line"
exit 1
;;
*)
compiler.print_error "unknown keyword '$keyword'"
compiler.cleanup
exit 1
;;
esac
Expand Down

0 comments on commit 5b3275a

Please sign in to comment.