blob: 14d08ac5602fd7d47f51d12e25610059dced26be (
plain)
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
|
#!/bin/sh
# clean up unnecessary data
# shellcheck disable=SC2119,SC2120
# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"
# we only clean if run interactive or if no one is logged in
if ! tty -s && \
[ -n "$(users)" ]; then
>&2 echo 'Skipping clean up.'
exit
fi
if [ -s "${work_dir}/build-master-sanity" ]; then
>&2 echo 'Build master is not sane.'
exit
fi
# Lock the database - we should not run in parallel with db-update.
exec 9> "${package_database_lock_file}"
# shellcheck disable=SC2086
if ! verbose_flock -n 9; then
>&2 echo 'come back (shortly) later - I cannot lock package database.'
exit 0
fi
# only keep newest logs per failed package and fail_reason
# shellcheck disable=SC2016
{
printf 'DELETE `failed_builds`'
printf ' FROM `failed_builds`'
printf ' LEFT JOIN ('
printf 'SELECT'
printf ' `failed_builds`.`reason`,'
printf '`failed_builds`.`build_assignment`,'
printf ' MAX(`failed_builds`.`date`) AS `max_date`'
printf ' FROM `failed_builds`'
printf ' GROUP BY CONCAT(`failed_builds`.`reason`,"-",`failed_builds`.`build_assignment`)'
printf ') AS `last_log_q`'
printf ' AND `last_log_q`.`%s`=`failed_builds`.`%s`' \
'max_date' 'date' \
'reason' 'reason' \
'build_assignment' 'build_assignment' \
| sed '
s/^ AND / ON /
'
printf ' WHERE `last_log_q`.`reason` IS NULL;\n'
} | \
mysql_run_query
# remove logs where package is not broken/locked anymore
{
find "${build_log_directory}/error" -maxdepth 1 -type f -printf 'file %f\n'
# shellcheck disable=SC2016
{
printf 'SELECT "mysql",`failed_builds`.`log_file`'
printf ' FROM `failed_builds`;\n'
} | \
mysql_run_query | \
tr '\t' ' '
} | \
sort -k2,2 -k1,1 | \
uniq -uf 1 | \
sed -n '
s/^file //
T
p
' | \
while read -r file; do
rm "${build_log_directory}/error/${file}"
done
# Release database lock.
flock -u 9 || true
# only keep namcap logs of last 2 weeks for succeeded packages
find "${build_log_directory}/success" -maxdepth 1 -type f -mtime +14 \
-not -exec zgrep -q '^+.*ELF file .* has text relocations' '{}' \; \
-delete
exit 0
|