aboutsummaryrefslogtreecommitdiff
path: root/cleanup
blob: 24ae9f98730ed26d50b7400104b2a6c9a99e3800 (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
88
89
90
91
92
93
94
95
#!/bin/bash

# Copyright (C) 2014, Linaro Limited.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Author: Andrew McDermott <andrew.mcdermott@linaro.org>

progname=$(basename $0)
SCRIPTPATH=$(cd $(dirname $0); pwd -P)
PATH=$SCRIPTPATH:$SCRIPTPATH/jtreg-bin/jtreg/bin:$PATH

: ${TOP_DIR:?"Must specify TOP_DIR (e.g., TOP_DIR=$HOME/openjdk8-aarch64 $progname)"}

source $SCRIPTPATH/common.sh

function actual_date() {
    echo $(doy2date $(basename $1) $(basename $2) "%a, %d %b %y 00:01:00")
}

function reset_date() {
    for i in $@; do
	for j in $i/*; do
	    find $j -maxdepth 0 -exec touch --date="$(actual_date $i $j)" {} \;
	done
    done
}

# Although we want a cleanup to remove based on age, we don't won't to
# delete results if that would leave us with less than ${DAYS} to look
# at in the published reports.

function clean_dirs() {
    for i in "$@"; do
	echo -e "\nCleanup: $i"
	tfile=$(mktemp /tmp/$(basename $i).$$.XXXXXXXX)
	find $i -maxdepth 2 -mindepth 2 -print | sort -n >> $tfile
	nentries=$(cat $tfile | wc -l)
	if [ $nentries -gt $DAYS ]; then
	    echo -e "\twhich has $nentries entries and is > MAX=$DAYS"
	    n=$(($nentries - $DAYS))
	    cat $tfile | sed 's/^/\t/'
	    echo -e "\tRemoving $n entries"
	    sed -n "1,${n}p" $tfile | while read; do
		# Sanity check.
		# Patterns to clean up are only $YEAR/$DAY_OF_YEAR
		if [[ $REPLY =~ \/[[:digit:]]{4}\/[[:digit:]]{3}$ ]]; then
		    echo -e "\tRemoving: $REPLY"
		    rm -rf $REPLY
		fi
	    done
	fi
	rm -f $tfile
    done
}

shopt -s globstar
shopt -s nullglob

# Patterns to clean up are $YEAR/$DAY_OF_YEAR

reset_date $TOP_DIR/reports/*/*/*/*
reset_date $TOP_DIR/builds/*/*
reset_date $TOP_DIR/src/*
reset_date $TOP_DIR/summary/*

clean_dirs $TOP_DIR/reports/*/*/*
clean_dirs $TOP_DIR/builds/*
clean_dirs $TOP_DIR/src
clean_dirs $TOP_DIR/metadata
clean_dirs $TOP_DIR/summary

find $TOP_DIR/reports -maxdepth 5 -type d -empty -print -delete
find $TOP_DIR/builds -maxdepth 3 -type d -empty -print -delete
find $TOP_DIR/src -maxdepth 2 -type d -empty -print -delete
find $TOP_DIR/summary -maxdepth 2 -type d -empty -print -delete

if `command -v tree >/dev/null 2>&1`; then
    tree -d -fl -P '[0-9]{3}' -L 5 $TOP_DIR/reports
    tree -d -fl -P '[0-9]{3}' -L 3 $TOP_DIR/builds
    tree -d -fl -P '[0-9]{3}' -L 2 $TOP_DIR/src
    tree -d -fl -P '[0-9]{3}' -L 2 $TOP_DIR/summary
fi