2 ##############################################################################
3 # Copyright (c) 2016 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 # Clean the build cache according to its expiry date. Invoke with the cache
12 # directory as the first argument.
15 echo "No cache directory specified, exiting..."
19 echo "Operating on cache $CACHEDIR"
25 echo "Step 1, cleaning orphaned meta and blob files"
26 ls *.meta *.blob | sed 's/\..*//' | sort | uniq -u | xargs -n 1 -I {} sh -c "rm -vf {}.*"
27 echo "Step 2, cleaning expired files"
28 for cache in $(ls -1 *.meta | sed 's/\..*//')
32 expiry=$(grep Expires: $meta | sed 's/Expires: *//')
33 if [ $expiry -le $NOW ]; then
34 echo "$cache expired $(date -d "@$expiry"), removing..."