From de6258290571377ba1e2c6a934ff9cb15d51df0a Mon Sep 17 00:00:00 2001 From: Tomasz Gajewski Date: Fri, 19 Feb 2021 23:51:04 +0100 Subject: [PATCH] prepare_port: simple cache for downloads Fixes #4028 --- tool/ports/mk/install.mk | 13 ++++++++++++- tool/ports/mk/prepare_single_port.mk | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tool/ports/mk/install.mk b/tool/ports/mk/install.mk index 6fe5271abf..c4501ce6ab 100644 --- a/tool/ports/mk/install.mk +++ b/tool/ports/mk/install.mk @@ -188,16 +188,24 @@ _svn_dir = $(call _assert,$(DIR($1)),Missing declaration of DIR($*)) _file_name = $(call _prefer,$(NAME($1)),$(notdir $(URL($1)))) +# # Some downloads are available via HTTPS only, but wget < 3.14 does not support # server-name identification, which is used by some sites. So, we disable # certificate checking in wget and check the validity of the download via SIG # or SHA. +# +# Successful and integrity-checked downloads are cached at the +# GENODE_CONTRIB_CACHE directory. The combination of 'cp' and 'mv' when +# populating the cache prevents corrupted files in the cache when the disk is +# full. +# %.file: $(VERBOSE)test -n "$(URL($*))" ||\ ($(ECHO) "Error: Undefined URL for $(call _file_name,$*)"; false); $(VERBOSE)mkdir -p $(dir $(call _file_name,$*)) - $(VERBOSE)name=$(call _file_name,$*);\ + $(VERBOSE)name=$(call _file_name,$*); cached_name=$(GENODE_CONTRIB_CACHE)/$(SHA($*))_$$name; \ + (test -f $$name || ! test -f $$cached_name || cp $$cached_name $$name); \ (test -f $$name || $(MSG_DOWNLOAD)$(URL($*))); \ (test -f $$name || wget --quiet --no-check-certificate $(URL($*)) -O $$name) || \ ($(ECHO) Error: Download for $* failed; false) @@ -205,6 +213,9 @@ _file_name = $(call _prefer,$(NAME($1)),$(notdir $(URL($1)))) ($(ECHO) "$(SHA($*)) $(call _file_name,$*)" |\ sha256sum -c > /dev/null 2> /dev/null) || \ ($(ECHO) Error: Hash sum check for $* failed; false) + $(VERBOSE)name=$(call _file_name,$*); cached_name=$(GENODE_CONTRIB_CACHE)/$(SHA($*))_$$name; \ + mkdir -p $(GENODE_CONTRIB_CACHE); \ + (test -f $$cached_name || (cp $$name $$cached_name.tmp && mv $$cached_name.tmp $$cached_name)) ## diff --git a/tool/ports/mk/prepare_single_port.mk b/tool/ports/mk/prepare_single_port.mk index fe903ff981..a4c3f46754 100755 --- a/tool/ports/mk/prepare_single_port.mk +++ b/tool/ports/mk/prepare_single_port.mk @@ -9,6 +9,7 @@ # 'create_builddir' tool within the Genode source tree # export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../../..) +export GENODE_CONTRIB_CACHE ?= $(GENODE_DIR)/contrib/cache include $(GENODE_DIR)/tool/ports/mk/front_end.inc include $(GENODE_DIR)/tool/ports/mk/check_port_arg.inc