From 59b5377ab155e0a00f57287d8b55ca5b05f0974e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 13 Sep 2012 00:50:25 +0200 Subject: Be more careful about cleaning up. --- src/password-store.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/password-store.sh') diff --git a/src/password-store.sh b/src/password-store.sh index f9e13e4..ed86248 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -212,7 +212,9 @@ case "$command" in passfile="$PREFIX/$path.gpg" template="$program.XXXXXXXXXXXXX" - if [ -d /dev/shm -a -w /dev/shm -a -x /dev/shm ]; then + trap 'rm -rf "$tmp_dir" "$tmp_file"' INT TERM EXIT + + if [[ -d /dev/shm && -w /dev/shm && -x /dev/shm ]]; then tmp_dir="$(TMPDIR=/dev/shm mktemp -t $template -d)" else echo "Your system does not have /dev/shm, which means that it may" @@ -229,10 +231,7 @@ case "$command" in action="Added" if [[ -f $passfile ]]; then - if ! gpg -q -d -o "$tmp_file" --yes "$passfile"; then - rm -rf "$tmp_file" "$tmp_dir" - exit 1 - fi + gpg -q -d -o "$tmp_file" --yes "$passfile" || exit 1 action="Edited" fi ${EDITOR:-vi} "$tmp_file" @@ -240,7 +239,6 @@ case "$command" in echo "GPG encryption failed. Retrying." sleep 1 done - rm -rf "$tmp_file" "$tmp_dir" if [[ -d $GIT ]]; then git add "$passfile" -- cgit v1.2.3-59-g8ed1b