summaryrefslogtreecommitdiffstats
path: root/scripts/sstate-cache-cleanup.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/sstate-cache-cleanup.sh')
-rwxr-xr-xscripts/sstate-cache-cleanup.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/sstate-cache-cleanup.sh b/scripts/sstate-cache-cleanup.sh
new file mode 100755
index 0000000..4eb6aff
--- /dev/null
+++ b/scripts/sstate-cache-cleanup.sh
@@ -0,0 +1,56 @@
1#!/bin/bash
2############################################################################
3##
4## Copyright (C) 2017 The Qt Company Ltd.
5## Contact: https://www.qt.io/licensing/
6##
7## This file is part of the Boot to Qt meta layer.
8##
9## $QT_BEGIN_LICENSE:GPL$
10## Commercial License Usage
11## Licensees holding valid commercial Qt licenses may use this file in
12## accordance with the commercial license agreement provided with the
13## Software or, alternatively, in accordance with the terms contained in
14## a written agreement between you and The Qt Company. For licensing terms
15## and conditions see https://www.qt.io/terms-conditions. For further
16## information use the contact form at https://www.qt.io/contact-us.
17##
18## GNU General Public License Usage
19## Alternatively, this file may be used under the terms of the GNU
20## General Public License version 3 or (at your option) any later version
21## approved by the KDE Free Qt Foundation. The licenses are as published by
22## the Free Software Foundation and appearing in the file LICENSE.GPL3
23## included in the packaging of this file. Please review the following
24## information to ensure the GNU General Public License requirements will
25## be met: https://www.gnu.org/licenses/gpl-3.0.html.
26##
27## $QT_END_LICENSE$
28##
29############################################################################
30
31set -e
32
33if [ $# -lt 1 ]; then
34 echo "Usage: $0 <sstate-cache-dir(s)>"
35 echo "Remove all old files from <sstate-cache-dir(s)>"
36 exit 1
37fi
38
39DAYS_TO_KEEP=7
40NOW=$(date +%s)
41
42for cachedir in $@; do
43
44 if [ ! -d $cachedir ]; then
45 echo "$cachedir: No such directory"
46 continue
47 fi
48
49 # find the most recently modified file's timestamp
50 LATEST=$(find $cachedir -type f -printf '%T@\n' | sort -n | tail -1 | cut -f 1 -d'.')
51 # calculate days
52 TIMEOUT=$(( ($NOW - $LATEST) / 3600 / 24 + $DAYS_TO_KEEP ))
53 # delete all files older
54 find ${cachedir} -type f -atime +${TIMEOUT} -delete
55
56done