From e5285c920d30f471f6577cada77555ecfd420b60 Mon Sep 17 00:00:00 2001 From: eismann Date: Wed, 13 Sep 2023 22:20:33 +0200 Subject: [PATCH] Remove tempDir on Ctrl+C --- 1fichier.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/1fichier.sh b/1fichier.sh index fd9733e..3e7d547 100644 --- a/1fichier.sh +++ b/1fichier.sh @@ -53,13 +53,23 @@ removeCookies() { } +cancelDownload() { + echo "Download cancelled." + removeTempDir "${lastTempDir}" + exit 1 +} + + downloadFile() { + trap cancelDownload SIGINT SIGTERM + local url=${1} echo "Processing \"${url}\""... echo -n "Search for a circuit without wait time..." local baseDir=$(pwd) local tempDir=${baseDir}/$(mktemp --directory "tmp.XXX") + lastTempDir=${tempDir} local filenameRegEx='>Filename :<.*(.*).*>Date :<' local maxCount=500 @@ -129,6 +139,8 @@ downloadFile() { failedDownload "${baseDir}" "${url}" fi removeTempDir "${tempDir}" + + trap - SIGINT SIGTERM } @@ -147,6 +159,7 @@ if [ "${torPort}" = "" ] ; then fi echo "Tor is listening on port ${torPort}" +lastTempDir= downloadSource=${1} if [[ "${downloadSource}" =~ "1fichier.com" ]] ; then downloadFile "${downloadSource}"