pjproject_bundled: Retry download if previously saved tarball is bad
authorGeorge Joseph <gjoseph@digium.com>
Fri, 9 Dec 2016 14:14:09 +0000 (07:14 -0700)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 9 Dec 2016 14:16:39 +0000 (08:16 -0600)
If a tarball is corrupted during download, the makefile will attempt to
download it again. If the tarball somehow gets corrupted after it's
downloaded however, the makefile was just failing.  We now
retry the download.

ASTERISK-26653 #close

Change-Id: I1b24d454852d80186f60c5a65dc4624ea8a1c359

third-party/pjproject/Makefile

index 21bdf23..e24a5df 100644 (file)
@@ -87,29 +87,37 @@ SHELL_ECHO_PREFIX := echo '[pjproject] '
 
 _all: $(TARGETS)
 
+define verify_tarball
+       ($(SHELL_ECHO_PREFIX) Verifying $(TARBALL) &&\
+       tarball_sum=$$($(CAT) $(TARBALL) | $(MD5) | $(SED) -n -r -e "s/^([^ ]+)\s+.*/\1/gp") ;\
+       required_sum=$$($(SED) -n -r -e "s/^([^ ]+)\s+$(TARBALL_FILE)/\1/gp" $(PJMD5SUM)) ;\
+       if [ "$$tarball_sum" != "$$required_sum" ] ; then $(SHELL_ECHO_PREFIX) Verify failed ; exit 1 ;\
+       else $(SHELL_ECHO_PREFIX) Verify successful ; exit 0 ; fi; )
+endef
+
 define download_from_pjproject
-       ($(SHELL_ECHO_PREFIX) Downloading $(PJPROJECT_URL)/$(@F) to $@ ;\
-       $(DOWNLOAD_TO_STDOUT) $(call DOWNLOAD_TIMEOUT,5,10) $(PJPROJECT_URL)/$(@F) > $@ &&\
+       ($(SHELL_ECHO_PREFIX) Downloading $(TARBALL_URL) to $(TARBALL) ;\
+       $(DOWNLOAD_TO_STDOUT) $(call DOWNLOAD_TIMEOUT,5,10) $(TARBALL_URL) > $(TARBALL) &&\
        $(SHELL_ECHO_PREFIX) Downloading $(PJPROJECT_URL)/MD5SUM to $(PJMD5SUM) &&\
        $(DOWNLOAD_TO_STDOUT) $(call DOWNLOAD_TIMEOUT,5,10) $(PJPROJECT_URL)/MD5SUM.TXT > $(PJMD5SUM) &&\
-       ($(SHELL_ECHO_PREFIX) Verifying $@ &&\
-       tarball_sum=$$($(CAT) $@ | $(MD5) | $(SED) -n -r -e "s/^([^ ]+)\s+.*/\1/gp") ;\
-       required_sum=$$($(SED) -n -r -e "s/^([^ ]+)\s+$(@F)/\1/gp" $(PJMD5SUM)) ;\
-       if [ "$$tarball_sum" != "$$required_sum" ] ; then $(SHELL_ECHO_PREFIX) Verify failed ; exit 1 ; fi) &&\
-       $(SHELL_ECHO_PREFIX) Verify successful ; exit 0)
+       $(verify_tarball))
 endef
 
 .DELETE_ON_ERROR:
 
 DOWNLOAD_DIR := $(or $(EXTERNALS_CACHE_DIR),$(TMPDIR),$(wildcard /tmp),.)
-TARBALL = $(DOWNLOAD_DIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
+TARBALL_FILE = pjproject-$(PJPROJECT_VERSION).tar.bz2
+TARBALL = $(DOWNLOAD_DIR)/$(TARBALL_FILE)
+TARBALL_URL = $(PJPROJECT_URL)/$(TARBALL_FILE)
 PJMD5SUM = $(patsubst %.tar.bz2,%.md5,$(TARBALL))
 
 $(TARBALL): ../versions.mak
        $(CMD_PREFIX) $(download_from_pjproject) || (rm -rf $@ ;\
-       $(SHELL_ECHO_PREFIX) Retrying download ; sleep 3 ; $(download_from_pjproject))
+       $(SHELL_ECHO_PREFIX) Retrying download ; $(download_from_pjproject))
 
 source/.unpacked: $(DOWNLOAD_DIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
+       ($(verify_tarball)) || (rm -rf $@ ;\
+       $(SHELL_ECHO_PREFIX) Retrying download ; $(download_from_pjproject))
        $(ECHO_PREFIX) Unpacking $<
        -@rm -rf source pjproject-* >/dev/null 2>&1
        $(CMD_PREFIX) $(TAR) -xjf $<