From 9c33131ece34a52341b1a31606d56329371fcce8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 5 Jan 2015 20:28:36 -0500 Subject: librefetch: wasn't cleaning up temp files --- src/librefetch/librefetch | 13 ++++++------- test/librefetch-test.sh | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/librefetch/librefetch b/src/librefetch/librefetch index e2300e0..45df21b 100755 --- a/src/librefetch/librefetch +++ b/src/librefetch/librefetch @@ -25,7 +25,7 @@ setup_traps tmpfiles=() -trap "rm -f -- $(printf '%q ' "${tmpfiles[@]}")" EXIT +trap 'rm -f -- "${tmpfiles[@]}"' EXIT cmd=${0##*/} usage() { @@ -93,6 +93,7 @@ main() { ######################################################################## makepkg="$(modified_makepkg "$(which makepkg)")" + tmpfiles+=("$makepkg") # Mode: makepkg ######################################################## @@ -115,6 +116,7 @@ main() { */SRCBUILD) srcbuild="$(modified_srcbuild "$BUILDFILE")";; *) srcbuild="$(modified_pkgbuild "$BUILDFILE")";; esac + tmpfiles+=("$srcbuild") # Mode: checksums ###################################################### @@ -323,8 +325,7 @@ tidy_install_purge() { modified_makepkg() { local makepkg_orig=$1 - local makepkg_mine="$(mktemp --tmpdir "${0##*/}.XXXXXXXXXXX.makepkg")" - tmpfiles+=("$makepkg_mine") + local makepkg_mine="$(mktemp --tmpdir "${cmd}.XXXXXXXXXXX.makepkg")" { echo '#!/bin/bash' declare -f tidy_install_purge @@ -377,8 +378,7 @@ package() { cp -a "$srcdir"/*/ "$pkgdir/"; } modified_pkgbuild() { local pkgbuild=$1 - local srcbuild="$(mktemp "${pkgbuild%/*}/${0##*/}.XXXXXXXXXXX.PKGBUILD.2.SRCBUILD")" - tmpfiles+=("$srcbuild") + local srcbuild="$(mktemp "${pkgbuild%/*}/${cmd}.XXXXXXXXXXX.PKGBUILD.2.SRCBUILD")" printf '%s' "$pkgbuild_append" | cat "$pkgbuild" - > "$srcbuild" printf '%s\n' "$srcbuild" } @@ -388,8 +388,7 @@ modified_pkgbuild() { modified_srcbuild() { local orig=$1 - local srcbuild="$(mktemp "${orig%/*}/${0##*/}.XXXXXXXXXXX.SRCBUILD.2.SRCBUILD")" - tmpfiles+=("$srcbuild") + local srcbuild="$(mktemp "${orig%/*}/${cmd}.XXXXXXXXXXX.SRCBUILD.2.SRCBUILD")" sed -e '/PKGDEST=/d' -e '/PKGEXT=/d' < "$orig" > "$new" printf '%s\n' "$new" } diff --git a/test/librefetch-test.sh b/test/librefetch-test.sh index f8bb226..8dd957a 100644 --- a/test/librefetch-test.sh +++ b/test/librefetch-test.sh @@ -41,21 +41,31 @@ it_displays_help() { empty $tmpdir/stderr } -# This test also does a rough test of file order in the PKGBUILD, as -# well as making sure that it correctly keeps track of $BUILDDIR, -# $startdir, and $SRCDEST. -it_cleans_src_libre_first() { +# This test used to be called "it_cleans_src_libre_first", but let's +# be honest: it checks pretty much everything related to normal +# operation. +it_runs() { + local srcball=testpkg-1.0.tar.gz cp librefetch.d/* "$tmpdir/" cd "$tmpdir" - # create garbage + # Create garbage, to verifiy that it cleans src-libre first mkdir -p src-libre/foo touch src-libre/foo/file - # run librefetch + # Run librefetch makepkg -g - srcball=testpkg-1.0.tar.gz + # Verify that no temporary files were left around + not test -e librefetch.* + + # Verify: + # - The srcball was created... + # - ... and is in the correct directory + # - The srcball does not contain the garbage created earlier + # - The files in the srcball are in the correct order (if the + # order isn't ensured, then this would only sometimes fail, + # unfortunately). bsdtar tf "$tmpdir/srcdest/$srcball" > list-pkg.txt diff -u list.txt list-pkg.txt } -- cgit v1.2.3