From f4947236dc6e249062ad4dc5341e71f4fd8e50bf Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 7 Sep 2018 10:19:24 -0700 Subject: [PATCH] Keep cargo-target-cache size under 6GB-ish --- .buildkite/hooks/pre-command | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index bed5503fa5..57fa49f852 100644 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -7,6 +7,16 @@ # ( d=$HOME/cargo-target-cache/"$CARGO_TARGET_CACHE_NAME" + + if [[ -d $d ]]; then + du -hs "$d" + read -r cacheSizeInGB _ < <(du -s --block-size=1000000000 "$d") + if [[ $cacheSizeInGB -gt 5 ]]; then + echo "$d has gotten too large, removing it" + rm -rf "$d" + fi + fi + mkdir -p "$d"/target set -x rsync -a --delete --link-dest="$d" "$d"/target .