#!/bin/sh # # Prune the failure files of stale entries # # This must be called via: # # lockf -k ${pbd}/${arch}/${branch}/failure.lock ${pbc}/scripts/prunefailure ${arch} ${branch} ${buildid} # # to avoid racing with any package builds in progress that might try to append to # these files. # configurable variables pbc=${PORTBUILD_CHECKOUT:-/a/portbuild} pbd=${PORTBUILD_DATA:-/a/portbuild} cleanup() { echo "Problem writing new failure file!" rm -f failure.new exit 1 } if [ $# -ne 3 ]; then echo "prunefailure " exit 1 fi arch=$1 branch=$2 buildid=$3 shift 3 . ${pbc}/conf/server.conf . ${pbc}/conf/common.conf . ${pbd}/${arch}/portbuild.conf if [ -f ${pbd}/${arch}/${branch}/builds/${buildid}/portbuild.conf ]; then . ${pbd}/${arch}/${branch}/builds/${buildid}/portbuild.conf fi . ${pbc}/scripts/buildenv builddir=${pbd}/${arch}/${branch}/builds/${buildid} buildenv ${pbd} ${arch} ${branch} ${builddir} home=${pbd}/${arch}/${branch} cd $home pkgdir=${builddir}/packages/All index=${PORTSDIR}/${INDEXFILE} if [ ! -f $index ]; then echo "INDEX file $index does not exist, terminating!" exit 1 fi if [ "`wc -l $index | awk '{print $1}'`" -lt 9000 ]; then echo "INDEX file $index is corrupted, terminating!" exit 1 fi echo "===> Pruning old failure file" rm -f failure.new IFS='|' while read dir name ver olddate date count; do if [ -z "$dir" -o -z "$name" -o -z "$ver" -o -z "$olddate" -o -z "$date" -o -z "$count" ]; then echo Malformed entry "$dir|$name|$ver|$olddate|$date|$count" # Clean up the 'latest error log' symlink rm -f ${pbd}/${arch}/${branch}/latest/${dir} continue fi entry=$(grep "|/usr/ports/$dir|" $index) if [ -z "$entry" ]; then echo $dir not in $index rm -f ${pbd}/${arch}/${branch}/latest/${dir} continue fi newver=$(echo $entry | awk '{print $1}') if [ -e "${builddir}/packages/All/$newver${pkg_sufx}" ]; then echo "$newver package exists, should not still be here!" rm -f ${pbd}/${arch}/${branch}/latest/${dir} continue fi if grep -qxF $newver ${builddir}/duds.full; then echo "$newver listed in duds, should not be here" rm -f ${pbd}/${arch}/${branch}/latest/${dir} continue fi (echo "$dir|$name|$newver|$olddate|$date|$count" >> $home/failure.new) || cleanup done < $home/failure mv failure.new failure