• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
  • Help
    • Online help
    • Learn Git
    • Welcome to Bitbucket
    • Keyboard shortcuts
  • Log In
Alexander Dahl
  1. Alexander Dahl

buildroot

Public
Actions
  • Clone
  • Compare

Learn more about cloning repositories

You have read-only access

Navigation
  • Source
  • Commits
  • Branches
  • All Branches Graph
  • Forks
  1. Alexander Dahl
  2. buildroot

Source

buildroot/support/download/dl-wrapper
Yann E. MORINYann E. MORIN committed 78b92e5055412 Dec 2014
Raw file
Source viewDiff to previous
 
1
#!/usr/bin/env bash
2
​
3
# This script is a wrapper to the other download backends.
4
# Its role is to ensure atomicity when saving downloaded files
5
# back to BR2_DL_DIR, and not clutter BR2_DL_DIR with partial,
6
# failed downloads.
7
#
8
# Call it with -h to see some help.
9
​
10
# To avoid cluttering BR2_DL_DIR, we download to a trashable
11
# location, namely in $(BUILD_DIR).
12
# Then, we move the downloaded file to a temporary file in the
13
# same directory as the final output file.
14
# This allows us to finally atomically rename it to its final
15
# name.
16
# If anything goes wrong, we just remove all the temporaries
17
# created so far.
18
​
19
# We want to catch any unexpected failure, and exit immediately.
20
set -e
21
​
22
main() {
23
    local OPT OPTARG
24
    local backend output
25
​
26
    # Parse our options; anything after '--' is for the backend
27
    while getopts :hb:o: OPT; do
28
        case "${OPT}" in
29
        h)  help; exit 0;;
30
        b)  backend="${OPTARG}";;
31
        o)  output="${OPTARG}";;
32
        :)  error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
33
        \?) error "unknown option '%s'\n" "${OPTARG}";;
34
        esac
35
    done
36
    # Forget our options, and keep only those for the backend
37
    shift $((OPTIND-1))
38
​
39
    if [ -z "${backend}" ]; then
40
        error "no backend specified, use -b\n"
41
    fi
42
    if [ -z "${output}" ]; then
43
        error "no output specified, use -o\n"
44
    fi
45
​
46
    # tmpd is a temporary directory in which backends may store intermediate
47
    # by-products of the download.
48
    # tmpf is the file in which the backends should put the downloaded content.
49
    # tmpd is located in $(BUILD_DIR), so as not to clutter the (precious)
50
    # $(BR2_DL_DIR)
51
    # We let the backends create tmpf, so they are able to set whatever
52
    # permission bits they want (although we're only really interested in
53
    # the executable bit.)
54
    tmpd="$(mktemp -d "${BUILD_DIR}/.${output##*/}.XXXXXX")"
55
    tmpf="${tmpd}/output"
56
​
57
    # Helpers expect to run in a directory that is *really* trashable, so
58
    # they are free to create whatever files and/or sub-dirs they might need.
59
    # Doing the 'cd' here rather than in all backends is easier.
60
    cd "${tmpd}"
61
​
62
    # If the backend fails, we can just remove the temporary directory to
63
    # remove all the cruft it may have left behind. Then we just exit in
  • Git repository management for enterprise teams powered by Atlassian Bitbucket
  • Atlassian Bitbucket v6.7.2
  • Documentation
  • Request a feature
  • About
  • Contact Atlassian
Atlassian

Everything looks good. We'll let you know here if there's anything you should know about.