index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rwxr-xr-x | contrib/wget-xdelta.sh | 47 | ||||
-rw-r--r-- | etc/makepkg.conf.in | 2 | ||||
-rw-r--r-- | scripts/makepkg.in | 47 |
diff --git a/contrib/wget-xdelta.sh b/contrib/wget-xdelta.sh new file mode 100755 index 00000000..d99dd3cc --- /dev/null +++ b/contrib/wget-xdelta.sh @@ -0,0 +1,47 @@ +#!/bin/bash +o=$(basename $1) +u=$2 +CARCH="i686" # Hmmm where to get this from? /etc/makepkg.conf? +cached_file="" +# Only check for pkg.tar.gz files in the cache, we download db.tar.gz as well +if [[ "$o" =~ "pkg.tar.gz" ]] # if $o contains pkg.tar.gz +then + pkgname=${o%-*-[0-9]-${CARCH}.pkg.tar.gz.part} # Parse out the package name + newend=${o##$pkgname-} # Parse out everything following pkgname + new_version=${newend%-${CARCH}.pkg.tar.gz.part} # Strip off .pkg.tar.gz.part leaving version + url=${u%/*} + for cached_file in $(ls -r /var/cache/pacman/pkg/${pkgname}-*-${CARCH}.pkg.tar.gz 2>/dev/null); do + # just take the first one, by name. I suppose we could take the latest by date... + oldend=${cached_file##*/$pkgname-} + old_version=${oldend%-${CARCH}.pkg.tar.gz} + if [ "$old_version" = "$new_version" ]; then + # We already have the new version in the cache! Just continue the download. + cached_file="" + fi + break + done +fi +if [ "$cached_file" != "" ]; then + # Great, we have a cached file, now calculate a patch name from it + delta_name=$pkgname-${old_version}_to_${new_version}-${CARCH}.delta + # try to download the delta + if wget --passive-ftp -c $url/$delta_name; then + # Now apply the delta to the cached file to produce the new file + echo Applying delta... + if xdelta patch $delta_name $cached_file $o; then + # Remove the delta now that we are finished with it + rm $delta_name + else + # Hmmm. xdelta failed for some reason + rm $delta_name + # just download the file + wget --passive-ftp -c -O $o $u + fi + else + # just download the file + wget --passive-ftp -c -O $o $u + fi +else + # just download the file + wget --passive-ftp -c -O $o $u +fi diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 2fc796e1..b68b937e 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -46,7 +46,7 @@ CXXFLAGS="-@ARCHSWITCH@=@CARCHFLAGS@ -mtune=generic -O2 -pipe" #-- color: Colorize output messages #-- ccache: Use ccache to cache compilation # -BUILDENV=(fakeroot !distcc color !ccache) +BUILDENV=(fakeroot !distcc color !ccache !xdelta) # #-- If using DistCC, your MAKEFLAGS will also need modification. In addition, #-- specify a space-delimited list of hosts running in the DistCC cluster. diff --git a/scripts/makepkg.in b/scripts/makepkg.in index 00e7b443..8c573461 100644 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -594,6 +594,53 @@ create_package() { error "$(gettext "Failed to create package file.")" exit 1 # TODO: error code fi + + create_xdelta "$pkg_file" +} + +create_xdelta() { + if [ "$(check_buildenv xdelta)" != "y" ]; then + return + fi + + # Check to see if we have any old versions to create deltas with + local pkg_file=$1 + local base_file="" + local delta_file="" + local cache_dir="/var/cache/pacman/pkg" + local latest_version="" + local old_versions=( $(ls ${cache_dir}/${pkgname}-*-${CARCH}.${PKGEXT} 2>/dev/null; ls ${PKGDEST}/${pkgname}-*-${CARCH}.${PKGEXT} 2>/dev/null) ) + + local old_file dirname filename namend old_version + for old_file in "${old_versions[@]}"; do + dirname=$(dirname $old_file) + filename=$(basename $old_file) + namend=${filename#"$pkgname-"} + old_version=${namend%-"${CARCH}.${PKGEXT}"} + + # old_version may include the target package, only use the old versions + if [ "$old_version" != "$pkgver-$pkgrel" ] && [[ "$old_version" > "$latest_version" ]]; then + latest_version=$old_version + base_file=$old_file + delta_file=$PKGDEST/$pkgname-${old_version}_to_$pkgver-$pkgrel-${CARCH}.delta + fi + done + + if [ "$delta_file" != "" ]; then + msg "Making delta from version $latest_version" + # xdelta will decompress base_file & pkg_file into TMP_DIR (or /tmp if TMP_DIR is unset) + # then perform the delta on the resulting tars + xdelta delta $base_file $pkg_file $delta_file + # Generate the final gz using xdelta for compression. xdelta will be our common + # denominator compression utility between the packager and the users + # + # makepkg and pacman must use the same compression algorithm or the delta generated + # package may not match, producing md5 checksum errors. + # + xdelta patch $delta_file $base_file $pkg_file + else + msg "No previous version found, skipping xdelta" + fi } create_srcpackage() { |