clean_disk_cache.sh 895 B

12345678910111213141516171819202122
  1. #!/usr/bin/env bash
  2. #
  3. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  4. # Exceptions. See /LICENSE for license information.
  5. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. #
  7. # Clean out any files in the Bazel disk cache which haven't been used for over
  8. # thirty days.
  9. set -eu
  10. # Default to the same directory in the project `.blazerc`, but you can set this
  11. # environment variable to override that.
  12. : ${BAZEL_DISK_CACHE_PATH:=~/.cache/carbon-lang-build-cache}
  13. # As a courtesy, compute and print some approximate stats.
  14. total_file_count=$(find "$BAZEL_DISK_CACHE_PATH" -type f | wc -l)
  15. stale_file_count=$(find "$BAZEL_DISK_CACHE_PATH" -type f -atime +30 | wc -l)
  16. echo "Removing $stale_file_count files out of $total_file_count total."
  17. # Just re-running the find is simpler than managing any state.
  18. find "$BAZEL_DISK_CACHE_PATH" -type f -atime +30 -delete