about summary refs log tree commit diff
path: root/xpkgdiff
diff options
context:
space:
mode:
authorclassabbyamp <void@placeviolette.net>2022-09-02 04:51:49 -0400
committerLeah Neukirchen <leah@vuxu.org>2022-09-02 16:04:03 +0200
commit8f5e62949a7ee88b85cf45a62617026549e3040a (patch)
treebe6e1b1cf7397234a369961555f92cfce713846c /xpkgdiff
parentd9a71e0c17a53c08420902ee482df45a2c1b8324 (diff)
downloadxtools-8f5e62949a7ee88b85cf45a62617026549e3040a.tar.gz
xtools-8f5e62949a7ee88b85cf45a62617026549e3040a.tar.xz
xtools-8f5e62949a7ee88b85cf45a62617026549e3040a.zip
xpkgdiff: clean up even on error
Diffstat (limited to 'xpkgdiff')
-rwxr-xr-xxpkgdiff12
1 files changed, 8 insertions, 4 deletions
diff --git a/xpkgdiff b/xpkgdiff
index 9072b34..581366e 100755
--- a/xpkgdiff
+++ b/xpkgdiff
@@ -6,13 +6,15 @@ usage() {
 	exit 1
 }
 
+cleanup() {
+	rm -rf $TMPDIR
+}
+
 : ${DIFF:="diff -u --color"}
 
 # by default, don't sort
 SORT='cat'
 
-TMPDIR=$(mktemp --tmpdir -d "xpkgdiff.XXXXX")
-
 while getopts Sc:fhp:rtx flag; do
 	case $flag in
 		S) QUERY='--show' ;;
@@ -31,6 +33,10 @@ shift $(($OPTIND - 1))
 [ "$#" -eq 0 ] && usage
 [ -z "$QUERY" ] && usage
 
+TMPDIR=$(mktemp --tmpdir -d "xpkgdiff.XXXXX")
+
+trap cleanup EXIT INT TERM
+
 if [ "$QUERY" = '--deps' ] && [ -n "$FULLTREE" ]; then
 	QUERY='--fulldeptree --deps'
 fi
@@ -80,5 +86,3 @@ else
 fi
 
 $DIFF $TMPDIR/$FILE1 $TMPDIR/$FILE2
-
-rm -rf $TMPDIR