index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | scripts/pkgdelta.sh.in | 99 |
diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in index 992c85f3..2fd116cb 100644 --- a/scripts/pkgdelta.sh.in +++ b/scripts/pkgdelta.sh.in @@ -30,6 +30,13 @@ declare -r myver='@PACKAGE_VERSION@' QUIET=0 +# minimal of package before deltas are generated (bytes) +min_pkg_size=$((1024*1024)) + +# percent of new package above which the delta will be discarded +max_delta_size=70 + + # ensure we have a sane umask set umask 0022 @@ -38,11 +45,16 @@ m4_include(library/output_format.sh) # print usage instructions usage() { printf "pkgdelta (pacman) %s\n\n" "$myver" - printf -- "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")" + printf -- "$(gettext "Usage: pkgdelta [options] <package1> <package2>\n")" printf -- "$(gettext "\ pkgdelta will create a delta file between two packages.\n\ This delta file can then be added to a database using repo-add.\n\n")" printf -- "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")\n" + echo + printf -- "$(gettext "Options:\n")" + printf -- " -q ""$(gettext "quiet\n")" + printf -- " --min-pkg-size ""$(gettext "minimal of package before deltas are generated (bytes)\n")" + printf -- " --max-delta-size ""$(gettext "percent of new package above which the delta will be discarded\n")" } version() { @@ -53,6 +65,10 @@ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } +isnumeric() { + [[ $1 != *[!0-9]* ]] +} + read_pkginfo() { pkgname= pkgver= arch= @@ -93,6 +109,13 @@ create_xdelta() newver="$pkgver" newarch="$arch" + pkgsize="$(@SIZECMD@ -L "$newfile")" + + if ((pkgsize < min_pkg_size)); then + msg "$(gettext "Skipping delta creation for small package: %s - size %s")" "$newname" "$pkgsize" + return 0 + fi + if [[ $oldname != "$newname" ]]; then error "$(gettext "The package names don't match : '%s' and '%s'")" "$oldname" "$newname" return 1 @@ -109,46 +132,78 @@ create_xdelta() fi msg "$(gettext "Generating delta from version %s to version %s")" "$oldver" "$newver" - deltafile="$(dirname $newfile)/$pkgname-${oldver}_to_${newver}-$arch.delta" + deltafile=$(dirname "$newfile")/$pkgname-${oldver}_to_${newver}-$arch.delta local ret=0 xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$? if (( ret )); then error "$(gettext "Delta could not be created.")" return 1 - else - msg "$(gettext "Generated delta : '%s'")" "$deltafile" - (( QUIET )) && echo "$deltafile" fi + + deltasize="$(@SIZECMD@ -L "$deltafile")" + + if ((max_delta_size * pkgsize / 100 < deltasize)); then + msg "$(gettext "Delta package larger than maximum size. Removing.")" + rm -f "$deltafile" + return 0 + fi + + msg "$(gettext "Generated delta : '%s'")" "$deltafile" + (( QUIET )) && echo "$deltafile" + return 0 } -case "$1" in - -h|--help) usage; exit 0 ;; - -V|--version) version; exit 0 ;; - -q|--quiet) QUIET=1; shift ;; -esac - -if (( $# != 2 )); then +declare -a args + +# parse arguments +while (( $# )); do + case "$1" in + -h|--help) usage; exit 0 ;; + -V|--version) version; exit 0 ;; + -q|--quiet) QUIET=1;; + --min-pkg-size) + if ! isnumeric "$2"; then + echo "invalid argument '$2' for option -- '$1'" + exit 1 + fi + min_pkg_size=$2 + shift + ;; + --max-delta-size) + arg=$(echo "$2" | awk '{print $1 * 100}') + if ! isnumeric "$arg" || (($arg > 200)); then + echo "invalid argument '$2' for option -- '$1'" + exit 1 + fi + max_delta_size=$arg + shift + ;; + --) shift; args+=("$@"); break 2 ;; + -*) echo "invalid option -- '$1'"; usage; exit 1 ;; + *) args+=("$1");; + esac + shift +done + +if (( ${#args[@]} != 2 )); then usage exit 1 fi -if [[ ! -f $1 ]]; then - error "$(gettext "File '%s' does not exist")" "$1" - exit 1 -fi - -if [[ ! -f $2 ]]; then - error "$(gettext "File '%s' does not exist")" "$2" - exit 1 -fi +for i in "${args[@]}"; do + if [[ ! -f $i ]]; then + error "$(gettext "File '%s' does not exist")" "$i" + exit 1 + fi +done if ! type xdelta3 &>/dev/null; then error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")" exit 1 fi -create_xdelta "$1" "$2" +create_xdelta "${args[@]}" # vim: set ts=2 sw=2 noet: |