clean_disk_cache.sh 882 B

1234567891011121314151617181920
  1. #!/bin/bash -eu
  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. # Default to the same directory in the project `.blazerc`, but you can set this
  10. # environment variable to override that.
  11. : ${BAZEL_DISK_CACHE_PATH:=~/.cache/carbon-lang-build-cache}
  12. # As a courtesy, compute and print some approximate stats.
  13. total_file_count=$(find "$BAZEL_DISK_CACHE_PATH" -type f | wc -l)
  14. stale_file_count=$(find "$BAZEL_DISK_CACHE_PATH" -type f -atime +30 | wc -l)
  15. echo "Removing $stale_file_count files out of $total_file_count total."
  16. # Just re-running the find is simpler than managing any state.
  17. find "$BAZEL_DISK_CACHE_PATH" -type f -atime +30 -delete