Bug#128818: partial patches - server application
Andreas Barth wrote:
with ideas and code (and a lot more) from Anthony, I was able to put
together the server part for partial patches in a way that it seems to
me that it might be included in dak. The resulting files are available
from
deb http://merkel.debian.org/~aba/debian sid main contrib non-free
(or any other combination of suites and components you like)
So here's a script to make use of them:
---
#!/bin/sh
file="$1"
index="$2"
patchurl="${3%/}"
patch=$(tempfile)
sizeof () {
wc -c "$1" | sed 's/^ *//;s/ .*//'
}
c_sha1=""
c_size="-1"
cur_sha1 () {
if [ "$c_sha1" = "" ]; then
c_sha1=$(sha1sum < "$file")
fi
echo $c_sha1
}
cur_size () {
c2_size=$(sizeof "$file")
if [ $c2_size != $c_size ]; then
c_size=$c2_size
c_sha1=""
fi
echo $c_size
}
patch_sha1_size () {
sed -n '/^SHA1-Patches:/,/^[^ ]/'"s/^ \([^ ]*\) *\([^ ]*\) $1\$/\1
\2/p" "$index"
}
sed -n '/^SHA1-History:/,/^[^ ]/s/^ / /p' "$index" |
while read n_sha1 n_size n_patch; do
echo "try: $n_patch"
if [ $(cur_size) = "$n_size" ]; then
if true || [ $(cur_sha1) = "$n_sha1" ]; then
curl -s "$patchurl/$n_patch.diff.gz" | zcat > $patch
p_size=$(sizeof $patch)
p_sha1=$(sha1sum < $patch)
if [ "$p_sha1 $p_size" = "$(patch_sha1_size $n_patch)" ]; then
echo "applying patch $n_patch"
(cat $patch; echo "wq") | ed "$file" >/dev/null
c_size=0
fi
fi
fi
done
rm -f "$patch"
---
If the script's installed in /usr/local/bin/untiffani, usage is
something like:
---
url=http://merkel.debian.org/~aba/debian
tmp=$(tempfile) || exit
cd /var/lib/apt/lists
for p in *_Packages; do
path=${p##*_dists_}
if [ "$path" = "$p" ]; then continue; fi
path=$(echo ${path%_Packages} | tr _ /)
>"$tmp"
url2="${url}/dists/${path}/diff"
url2=$(echo "$url2" | sed 's/testing/sarge/;s/unstable/sid/')
wget -q -o "$tmp" "${url2}/Index"
if [ -s "$tmp" ]; then
cp "$p" "${p.bak}"
/usr/local/bin/untiffani "$p" "$tmp" "${url2}"
fi
done
rm -f "$tmp"
apt-get update
---
It's uh, rather untested. If you try it and it actually works (or you
fix it so it works), might be worth posting a followup if nobody else
has already.
For comparison, today's update of unstable/main/i386/Packages.bz2 goes
from downloading the full 2.5MB to downloading a 2kB Index file, and a
15kB patch.
Note that the ~aba url is only updated about now every day, and if it
and your mirror are out of sync, you'll likely end up unhappy.
Cheers,
aj
Reply to: