Jim Klimov
2016-04-28 bd7dc69e49d01a29b0c71d9a02a95739cbc186cb
Extend userland-fetch with a --keep option to not delete files, and add a "gmake fetch" action to just download and verify (not remove) files
2 files modified
30 ■■■■ changed files
make-rules/prep-download.mk 11 ●●●●● patch | view | raw | blame | history
tools/userland-fetch 19 ●●●●● patch | view | raw | blame | history
make-rules/prep-download.mk
@@ -38,6 +38,12 @@
URL_SUFFIXES = $(subst COMPONENT_ARCHIVE_URL_,, \
        $(filter COMPONENT_ARCHIVE_URL_%, $(.VARIABLES)))
# Argument to "userland-fetch" script that causes it to download and verify
# files, but not to remove mismatches; good to save traffic when initially
# fetching a new archive just to learn what checksum to expect in Makefile.
#FETCH_KEEP ?= --keep
FETCH_KEEP ?=
# Template for download rules.
define download-rules
ifdef COMPONENT_ARCHIVE_URL$(1)
@@ -45,10 +51,13 @@
ARCHIVES += $$(COMPONENT_ARCHIVE$(1))
CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
fetch::    FETCH_KEEP=--keep
fetch::    $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
download::    $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
$$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)):    $(MAKEFILE_PREREQ)
    $$(FETCH) --file $$@ \
    $$(FETCH) $$(FETCH_KEEP) --file $$@ \
        $$(COMPONENT_ARCHIVE_URL$(1):%=--url %) \
        $$(COMPONENT_ARCHIVE_HASH$(1):%=--hash %) \
        $$(COMPONENT_SIG_URL$(1):%=--sigurl %) \
tools/userland-fetch
@@ -179,13 +179,14 @@
    user_agent_arg = None
    file_arg = None
    link_arg = False
    keep_arg = False
    hash_arg = None
    url_arg = None
    search_list = list()
    try:
        opts, args = getopt.getopt(sys.argv[1:], "a:f:h:ls:u:",
            ["file=", "link", "hash=", "search=", "url=",
        opts, args = getopt.getopt(sys.argv[1:], "a:f:h:lks:u:",
            ["file=", "link", "keep", "hash=", "search=", "url=",
            "user-agent="])
    except getopt.GetoptError, err:
        print str(err)
@@ -198,6 +199,8 @@
            file_arg = arg
        elif opt in [ "-l", "--link" ]:
            link_arg = True
        elif opt in [ "-k", "--keep" ]:
            keep_arg = True
        elif opt in [ "-h", "--hash" ]:
            hash_arg = arg
        elif opt in [ "-s", "--search" ]:
@@ -255,10 +258,14 @@
            print "    actual:   %s" % realhash
            print "    payload:  %s" % payloadhash
        try:
            os.remove(name)
        except OSError:
            pass
        if keep_arg == False:
            try:
                print "\nWARN: Removing the corrupt downloaded file"
                os.remove(name)
            except OSError:
                pass
        else:
            print "\nINFO: Keeping the downloaded file because asked to"
    sys.exit(1)