Merge pull request #1956 from pullmoll/hashcache

xbps-src: implement a by_sha256 hash cache
This commit is contained in:
Jürgen Buchmüller 2015-07-05 10:50:58 +02:00
commit b4c60f4798
3 changed files with 51 additions and 7 deletions

View file

@ -2,22 +2,29 @@
# the $distfiles variable and then verifies its sha256 checksum comparing # the $distfiles variable and then verifies its sha256 checksum comparing
# its value with the one stored in the $checksum variable. # its value with the one stored in the $checksum variable.
verify_cksum() { # Get the checksum for $curfile at index $dfcount
local curfile="$1" distfile="$2" dfcount="$3" filesum ckcount cksum found i get_cksum() {
local curfile="$1" dfcount="$2" ckcount cksum i
ckcount=0 ckcount=0
cksum=0
for i in ${checksum}; do for i in ${checksum}; do
if [ $dfcount -eq $ckcount -a -n "$i" ]; then if [ $dfcount -eq $ckcount -a -n "$i" ]; then
cksum=$i cksum=$i
found=yes
break
fi fi
ckcount=$(($ckcount + 1)) ckcount=$((ckcount + 1))
done done
if [ -z $found ]; then if [ -z "$cksum" ]; then
msg_error "$pkgver: cannot find checksum for $curfile.\n" msg_error "$pkgver: cannot find checksum for $curfile.\n"
fi fi
echo "$cksum"
}
# Verify the checksum for $curfile stored at $distfile and index $dfcount
verify_cksum() {
local curfile="$1" distfile="$2" dfcount="$3" filesum cksum
cksum=$(get_cksum $curfile $dfcount)
msg_normal "$pkgver: verifying checksum for distfile '$curfile'... " msg_normal "$pkgver: verifying checksum for distfile '$curfile'... "
filesum=$(${XBPS_DIGEST_CMD} $distfile) filesum=$(${XBPS_DIGEST_CMD} $distfile)
if [ "$cksum" != "$filesum" ]; then if [ "$cksum" != "$filesum" ]; then
@ -25,10 +32,25 @@ verify_cksum() {
msg_red "SHA256 mismatch for '$curfile:'\n$filesum\n" msg_red "SHA256 mismatch for '$curfile:'\n$filesum\n"
errors=$(($errors + 1)) errors=$(($errors + 1))
else else
if [ ! -f "$XBPS_SRCDISTDIR/by_sha256/$cksum" ]; then
mkdir -p "$XBPS_SRCDISTDIR/by_sha256"
ln -f "$distfile" "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}"
fi
msg_normal_append "OK.\n" msg_normal_append "OK.\n"
fi fi
} }
# Link an existing cksum $distfile for $curfile at index $dfcount
link_cksum() {
local curfile="$1" distfile="$2" dfcount="$3" filesum cksum
cksum=$(get_cksum $curfile $dfcount)
if [ -n "$cksum" -a -f "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}" ]; then
ln -f "$XBPS_SRCDISTDIR/by_sha256/${cksum}_${curfile}" "$distfile"
msg_normal "$pkgver: using known distfile $curfile.\n"
fi
}
hook() { hook() {
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version" local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
local dfcount=0 errors=0 local dfcount=0 errors=0
@ -53,7 +75,11 @@ hook() {
[ $? -eq 0 ] && break [ $? -eq 0 ] && break
msg_warn "$pkgver: ${curfile} is being already downloaded, waiting for 1s ...\n" msg_warn "$pkgver: ${curfile} is being already downloaded, waiting for 1s ...\n"
done done
# If distfile does not exist download it. # If distfile does not exist, try to link to it.
if [ ! -f "$distfile" ]; then
link_cksum $curfile $distfile $dfcount
fi
# If distfile does not exist, download it.
if [ ! -f "$distfile" ]; then if [ ! -f "$distfile" ]; then
msg_normal "$pkgver: fetching distfile '$curfile'...\n" msg_normal "$pkgver: fetching distfile '$curfile'...\n"
flock "${distfile}.part" $XBPS_FETCH_CMD "$f" flock "${distfile}.part" $XBPS_FETCH_CMD "$f"

View file

@ -0,0 +1,12 @@
# vim: set ts=4 sw=4 et:
update_hash_cache() {
local cache="$XBPS_SRCDISTDIR/by_sha256"
local distfile curfile
mkdir -p "$cache"
find "$XBPS_SRCDISTDIR" -type f | grep -v by_sha256 | while read -r distfile; do
cksum=$(cat "$distfile" | sha256sum | cut -d " " -f 1)
curfile="$(basename ${distfile})"
ln -vf "$distfile" "${cache}/${cksum}_${curfile}"
done
}

View file

@ -102,6 +102,9 @@ update-sys
update-check <pkgname> update-check <pkgname>
Check upstream site of <pkgname> for new releases. Check upstream site of <pkgname> for new releases.
update-hash-cache
Update the hash cache with existing source distfiles.
zap zap
Removes a masterdir but preserving ccache, distcc and host directories. Removes a masterdir but preserving ccache, distcc and host directories.
@ -697,6 +700,9 @@ case "$XBPS_TARGET" in
read_pkg read_pkg
update_check update_check
;; ;;
update-hash-cache)
update_hash_cache
;;
zap) zap)
masterdir_zap masterdir_zap
;; ;;