aboutsummaryrefslogtreecommitdiffstats
path: root/ci/clean_cache.sh
diff options
context:
space:
mode:
authorStefan K. Berg <stefan.k.berg@ericsson.com>2016-06-08 13:50:32 +0200
committerStefan K. Berg <stefan.k.berg@ericsson.com>2016-06-08 14:01:14 +0200
commit53d15c91c9896534fe9fb5cc7cd010b29f6f06a1 (patch)
tree6dfccb4879db58bd04ed9caaca4d177296fc42e0 /ci/clean_cache.sh
parentc4afb1da513ef3230432fff400ea231660b230c9 (diff)
Script to clean expired build cache items
Change-Id: I5e466c89c05eb4d637778218cfe03b88d569f331 Signed-off-by: Stefan K. Berg <stefan.k.berg@ericsson.com>
Diffstat (limited to 'ci/clean_cache.sh')
-rwxr-xr-xci/clean_cache.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/ci/clean_cache.sh b/ci/clean_cache.sh
new file mode 100755
index 000000000..177fe821b
--- /dev/null
+++ b/ci/clean_cache.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+##############################################################################
+# Copyright (c) 2016 Ericsson AB and others.
+# stefan.k.berg@ericsson.com
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Clean the build cache according to its expiry date. Invoke with the cache
+# directory as the first argument.
+
+if [ -z "$1" ]; then
+ echo "No cache directory specified, exiting..."
+ exit 1
+else
+ CACHEDIR=$1
+ echo "Operating on cache $CACHEDIR"
+fi
+
+NOW=$(date '+%s')
+
+cd $CACHEDIR
+echo "Step 1, cleaning orphaned meta and blob files"
+ls *.meta *.blob | sed 's/\..*//' | sort | uniq -u | xargs -n 1 -I {} sh -c "rm -vf {}.*"
+echo "Step 2, cleaning expired files"
+for cache in $(ls -1 *.meta | sed 's/\..*//')
+do
+ blob=${cache}.blob
+ meta=${cache}.meta
+ expiry=$(grep Expires: $meta | sed 's/Expires: *//')
+ if [ $expiry -le $NOW ]; then
+ echo "$cache expired $(date -d "@$expiry"), removing..."
+ rm -f $blob $meta
+ fi
+done
+