Ticket #68: dohttp.7

File dohttp.7, 3.7 KB (added by ony, 2 years ago)

added $GETDELTA_MIN_SIZE (in bytes) to allow skipping deltup on small files

Line 
1#!/bin/bash
2# vim: set sw=4 sts=4 et :
3
4# Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
5#
6# This file is part of the Paludis package manager. Paludis is free software;
7# you can redistribute it and/or modify it under the terms of the GNU General
8# Public License, version 2, as published by the Free Software Foundation.
9#
10# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13# details.
14#
15# You should have received a copy of the GNU General Public License along with
16# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17# Place, Suite 330, Boston, MA  02111-1307  USA
18
19export PATH="$(${PALUDIS_EBUILD_DIR}/utils/canonicalise ${PALUDIS_EBUILD_DIR}/utils/ ):${PATH}"
20source ${PALUDIS_EBUILD_DIR}/echo_functions.bash
21
22old_set=$-
23set -a
24for f in ${PALUDIS_BASHRC_FILES}; do
25    [[ -f "${f}" ]] && source "${f}"
26done
27[[ "${old_set}" == *a* ]] || set +a
28
29# If this is tarball sync, we don't need getdelta (at the moment)
30if [[ -z "${PN}" ]]; then
31    unset USE_GETDELTA
32fi
33
34www_size() {
35    HEAD "$1" | sed -n 's/Content-Length: //p'
36    return $?
37}
38
39# check GETDELTA_MIN_SIZE
40if [[ "$USE_GETDELTA" == "yes" ]] && [[ -n "$GETDELTA_MIN_SIZE" ]]; then
41    einfo_unhooked "Feature getdelta requested with minimum size $GETDELTA_MIN_SIZE"
42    _remote_size="$(www_size "$1")"
43    if [[ -n "$_remote_size" ]]; then
44        _local_size=0
45        if [[ -n "${PALUDIS_USE_SAFE_RESUME}" ]]; then
46            if [[ -f "${2}.-PARTIAL-" ]]; then
47                _local_size=$(wrapped_getfsize "${2}.-PARTIAL-")
48                einfo_unhooked "Found partially downloaded file with size $_local_size"
49            fi
50        fi
51        _download_size=$(($_remote_size - $_local_size))
52        einfo_unhooked "Need to download $_download_size bytes"
53        if [[ $_download_size -lt $GETDELTA_MIN_SIZE ]]; then
54            unset USE_GETDELTA
55            einfo_unhooked "Feature getdelta is prohibited"
56        fi
57    fi
58fi
59
60if [[ -n "${PALUDIS_USE_SAFE_RESUME}" ]] ; then
61    if [[ -f "${2}.-PARTIAL-" ]] ; then
62        if [[ $(wrapped_getfsize "${2}".-PARTIAL- ) -ge 4096 ]] ; then
63            einfo_unhooked "Attempting resume using ${2}.-PARTIAL-"
64        else
65            einfo_unhooked "Not attempting resume using ${2}.-PARTIAL- (too small)"
66            echo rm -f "${2}".-PARTIAL-
67            rm -f "${2}".-PARTIAL-
68        fi
69    fi
70
71    if [ "$USE_GETDELTA" == "yes" ]; then
72        echo /usr/bin/getdelta-paludis.sh "${1}" 1>&2
73        if /usr/bin/getdelta-paludis.sh "${1}" ; then
74            echo mv -f "${2}".-PARTIAL- "${2}"
75            mv -f "${2}".-PARTIAL- "${2}" >&/dev/null
76            exit 0
77        else
78            rm -f "${2}"
79            exit 1
80        fi
81    else
82        echo ${WGET_WRAPPER} ${LOCAL_WGET:-wget} ${EXTRA_WGET} -T 30 -t 1 --continue -O "${2}".-PARTIAL- "${1}" 1>&2
83        if ${WGET_WRAPPER} ${LOCAL_WGET:-wget} ${EXTRA_WGET} -T 30 -t 1 --continue -O "${2}".-PARTIAL- "${1}" ; then
84            echo mv -f "${2}".-PARTIAL- "${2}"
85            mv -f "${2}".-PARTIAL- "${2}"
86            exit 0
87        else
88            rm -f "${2}"
89            exit 1
90        fi
91    fi
92else
93    if [ "$USE_GETDELTA" == "yes" ]; then
94        echo /usr/bin/getdelta.sh "${1}" 1>&2
95        if /usr/bin/getdelta.sh "${1}" ; then
96            exit 0
97        else
98            rm -f "${2}"
99            exit 1
100        fi
101    else
102        echo ${WGET_WRAPPER} ${LOCAL_WGET:-wget} ${EXTRA_WGET} -T 30 -t 1 -O "${2}" "${1}" 1>&2
103        if ${WGET_WRAPPER} ${LOCAL_WGET:-wget} ${EXTRA_WGET} -T 30 -t 1 -O "${2}" "${1}" ; then
104            exit 0
105        else
106            rm -f "${2}"
107            exit 1
108        fi
109    fi
110fi