POL_Download_retry

Informations

Créateur Messages
petch
Développeur

Information

Cet installateur a été accepté par l'équipe.

Informations

Plate-formes :
Téléchargements : 1328813
Wine: System

Retours d'expérience

Description

Download with retry and resume:
- files are always downloaded with a ".part" suffix
- in case of retry, it then knows it has to resume download
- at the end of download, if hash matches the file is given its final filename, otherwise its renamed with ".failed" suffix and download can be retried
- if a ".failed" file is found when the script is restarted, an attempt is made to validate it with the hash (in case the script has been updated with a new hash)

Parameters:
#1. URL
#2. Local filename
#3. Expected MD5 hash
#4. Title

Code source

# 1: URL
# 2: filename
# 3: MD5 hash
# 4: Title

# Failed piece from previous download, maybe reference MD5 was corrected?
local FAILEDPIECE="$2.failed"
if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then
        POL_Debug_Message "Failed download found, trying to recover"
        POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4"
        if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then
                POL_Debug_Message "Download recovery successful"
                mv "$FAILEDPIECE" "$2"
        fi
fi

[ -e "$2" ] && return

local TMPPIECE="$2.part"
while true; do
        POL_System_wget "$1" "$4" --no-check-certificate --continue -O "$TMPPIECE"
        POL_Debug_Message "POL_System_wget exit code: $?"

        POL_SetupWindow_wait "$(eval_gettext 'Checking download integrity...')" "$4"
        if [ ! -e "$TMPPIECE" ]; then
                POL_Debug_Message "No downloaded file"
                DLMSG="$(eval_gettext 'Download failed')"
        elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then
                POL_Debug_Message "Downloaded file incomplete or corrupted"
                DLMSG="$(eval_gettext 'Download seems to be corrupted')"
                mv "$TMPPIECE" "$FAILEDPIECE"
        else
                POL_Debug_Message "Download completed successfully"
                mv "$TMPPIECE" "$2"
                [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE"
                break
        fi

        local OLD_APP_ANSWER="$APP_ANSWER"
        POL_SetupWindow_question "$DLMSG\n$(eval_gettext 'Retry?')" "$TITLE"
        [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$DLMSG"
        APP_ANSWER="$OLD_APP_ANSWER"
done

Contributions

Filters:

Contribuer
Membre Messages
petch Mardi 11 Aoüt 2015 à 18:06
petch
Développeur

Information

Cette mise à jour a été acceptée par l'équipe

Messages

Fix minor typo (POL_Debug_message => POL_Debug_Message)

Differences

@@ -6,10 +6,10 @@
 # Failed piece from previous download, maybe reference MD5 was corrected?
 local FAILEDPIECE="$2.failed"
 if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then
-        POL_Debug_message "Failed download found, trying to recover"
+        POL_Debug_Message "Failed download found, trying to recover"
         POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4"
         if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then
-                POL_Debug_message "Download recovery successful"
+                POL_Debug_Message "Download recovery successful"
                 mv "$FAILEDPIECE" "$2"
         fi
 fi
@@ -19,18 +19,18 @@
 local TMPPIECE="$2.part"
 while true; do
         POL_System_wget "$1" "$4" --no-check-certificate --continue -O "$TMPPIECE"
-        POL_Debug_message "POL_System_wget exit code: $?"
+        POL_Debug_Message "POL_System_wget exit code: $?"
 
         POL_SetupWindow_wait "$(eval_gettext 'Checking download integrity...')" "$4"
         if [ ! -e "$TMPPIECE" ]; then
-                POL_Debug_message "No downloaded file"
+                POL_Debug_Message "No downloaded file"
                 DLMSG="$(eval_gettext 'Download failed')"
         elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then
-                POL_Debug_message "Downloaded file incomplete or corrupted"
+                POL_Debug_Message "Downloaded file incomplete or corrupted"
                 DLMSG="$(eval_gettext 'Download seems to be corrupted')"
                 mv "$TMPPIECE" "$FAILEDPIECE"
         else
-                POL_Debug_message "Download completed successfully"
+                POL_Debug_Message "Download completed successfully"
                 mv "$TMPPIECE" "$2"
                 [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE"
                 break

Nouveau code source

# 1: URL
# 2: filename
# 3: MD5 hash
# 4: Title

# Failed piece from previous download, maybe reference MD5 was corrected?
local FAILEDPIECE="$2.failed"
if [ -n "$3" -a ! -e "$2" -a -e "$FAILEDPIECE" ]; then
        POL_Debug_Message "Failed download found, trying to recover"
        POL_SetupWindow_wait "$(eval_gettext 'Checking piece integrity...')" "$4"
        if [ "$(POL_MD5_file $FAILEDPIECE)" = "$3" ]; then
                POL_Debug_Message "Download recovery successful"
                mv "$FAILEDPIECE" "$2"
        fi
fi

[ -e "$2" ] && return

local TMPPIECE="$2.part"
while true; do
        POL_System_wget "$1" "$4" --no-check-certificate --continue -O "$TMPPIECE"
        POL_Debug_Message "POL_System_wget exit code: $?"

        POL_SetupWindow_wait "$(eval_gettext 'Checking download integrity...')" "$4"
        if [ ! -e "$TMPPIECE" ]; then
                POL_Debug_Message "No downloaded file"
                DLMSG="$(eval_gettext 'Download failed')"
        elif [ -n "$3" ] && [ "$(POL_MD5_file $TMPPIECE)" != "$3" ]; then
                POL_Debug_Message "Downloaded file incomplete or corrupted"
                DLMSG="$(eval_gettext 'Download seems to be corrupted')"
                mv "$TMPPIECE" "$FAILEDPIECE"
        else
                POL_Debug_Message "Download completed successfully"
                mv "$TMPPIECE" "$2"
                [ -e "$FAILEDPIECE" ] && rm "$FAILEDPIECE"
                break
        fi

        local OLD_APP_ANSWER="$APP_ANSWER"
        POL_SetupWindow_question "$DLMSG\n$(eval_gettext 'Retry?')" "$TITLE"
        [ "$APP_ANSWER" = "TRUE" ] || POL_Debug_Fatal "$DLMSG"
        APP_ANSWER="$OLD_APP_ANSWER"
done

Réponses