From d50a9e498894b178f4bbd7997efcda9f48a7b778 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Wed, 14 Jul 2021 11:16:44 +0200 Subject: [PATCH] more reliable cleanup on exit --- threadwatcher | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/threadwatcher b/threadwatcher index b1b9959..271d784 100755 --- a/threadwatcher +++ b/threadwatcher @@ -138,8 +138,7 @@ scan(){ wait done tac "$TMP_URLFILE" > "$URLFILE" - rm "$TMP_URLFILE" - rm /tmp/threadwatcher.lock + cleanup } prune(){ @@ -150,12 +149,12 @@ prune(){ done #Create lock file to stop override of URLFILE touch /tmp/threadwatcher.lock - ping -q -c 1 4channel.org > /dev/null|| { echo "Cannot connect to 4chan."; exit 1;} + ping -q -c 1 4channel.org > /dev/null|| { echo "Cannot connect to 4chan."; cleanup && exit 1;} if [ "$(wc -l < "$URLFILE")" -gt 0 ]; then echo "Pruning threads..." else echo "No threads to prune." - exit + cleanup && exit fi #tac used to prioritze newly added threads. @@ -176,7 +175,7 @@ prune(){ notify-send "threadwatcher" "Thread downloading to $(echo "$dl_location" | sed "s|$HOME|~|") is complete now." else echo "Cannot connect to 4chan." - exit 1 + cleanup && exit 1 fi continue else @@ -186,9 +185,7 @@ prune(){ rm /tmp/content$$ done tac "$TMP_URLFILE" > "$URLFILE" - rm "$TMP_URLFILE" - rm /tmp/threadwatcher.lock - + cleanup } add() { @@ -248,6 +245,11 @@ add() { fi } +cleanup(){ + rm -f /tmp/threadwatcher.lock + rm -f "$TMP_URLFILE" +} + case "$1" in "add") add "$2" "$3" scan;;