summaryrefslogtreecommitdiff
path: root/Tools/portbuild/scripts/prunefailure
blob: 3d559750bcf567673bb15ebbbfe7770cd1a78560 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
#
# Prune the failure and newfailure files of stale entries
#
# This must be called via:
#
#   lockf ${pb}/${arch}/${branch}/failure.lock ${pb}/scripts/prunefailure ${arch} ${branch}
#
# to avoid racing with any package builds in progress that might try to append to
# these files.

# configurable variables
pb=/var/portbuild

cleanup() {
    echo "Problem writing new failure file!"
    rm failure.new
    exit 1
}

if [ $# -ne 2 ]; then
    echo "prunefailure <arch> <branch>"
    exit 1
fi

arch=$1
branch=$2
shift 2

. ${pb}/${arch}/portbuild.conf
. ${pb}/scripts/buildenv

buildenv ${pb} ${arch} ${branch}

home=${pb}/${arch}/${branch}
cd $home

pkgdir=$home/packages/All
index=${PORTSDIR}/${INDEXFILE}

if [ "`wc -l $index | awk '{print $1}'`" -lt 9000 ]; then
    echo "INDEX is corrupted, terminating!"
    exit 1
fi

echo "===> Pruning old failure file"

rm -f failure.new
IFS='|'
while read dir name ver date count; do

    if [ -z "$dir" -o -z "$name" -o -z "$ver" -o -z "$date" -o -z "$count" ]; then
	echo Malformed entry "$dir|$name|$ver|$date|$count"
	continue
    fi

    entry=$(grep "|/usr/ports/$dir|" $index)
    if [ -z "$entry" ]; then
	echo $dir not in index
	continue
    fi

    newver=$(echo $entry | awk '{print $1}')

    if [ -e "$home/packages/All/$newver${PKGSUFFIX}" ]; then
	echo "$newver package exists, should not still be here!"
	continue
    fi

    if grep -q $newver $home/duds.orig; then
	echo "$newver listed in duds, should not be here"
	continue
    fi

    (echo "$dir|$name|$newver|$date|$count" >> $home/failure.new) || cleanup
done < $home/failure

mv failure.new failure

echo "===> Pruning old newfailure file"

rm -f newfailure.new
IFS='|'
while read dir name ver date; do
    if [ -z "$dir" -o -z "$name" -o -z "$ver" -o -z "$date" ]; then
	echo Malformed entry "$dir|$name|$ver|$date|$count"
	continue
    fi

    entry=$(grep "|/usr/ports/$dir|" $index)

    if [ -z "$entry" ]; then
	echo $dir not in index
	continue
    fi

    newver=$(echo $entry | awk '{print $1}')

    if [ -e "$home/packages/All/$newver${PKGSUFFIX}" ]; then
	echo "$newver package exists, should not still be here!"
	continue
    fi

    if grep -q $newver $home/duds.orig; then
	echo "$newver listed in duds, should not be here"
	continue
    fi

    (echo "$dir|$name|$newver|$date" >> $home/newfailure.new) || cleanup
done < $home/newfailure

mv newfailure.new newfailure