<commit_before># frozen_string_literal: true

require "utils/bottles"
require "utils/gems"
require "formula"
require "cask/cask_loader"
require "set"

CLEANUP_DEFAULT_DAYS = 30

module CleanupRefinement
  refine Pathname do
    def incomplete?
      extname.end_with?(".incomplete")
    end

    def nested_cache?
      directory? && %w[cargo_cache go_cache glide_home java_cache npm_cache gclient_cache].include?(basename.to_s)
    end

    def go_cache_directory?
      # Go makes its cache contents read-only to ensure cache integrity,
      # which makes sense but is something we need to undo for cleanup.
      directory? && %w[go_cache].include?(basename.to_s)
    end

    def prune?(days)
      return false unless days
      return true if days.zero?

      return true if symlink? && !exist?

      mtime < days.days.ago && ctime < days.days.ago
    end

    def stale?(scrub = false)
      return false unless resolved_path.file?

      if dirname.basename.to_s == "Cask"
        stale_cask?(scrub)<commit_msg>cleanup: clean go_mod_cache<commit_after># frozen_string_literal: true

require "utils/bottles"
require "utils/gems"
require "formula"
require "cask/cask_loader"
require "set"

CLEANUP_DEFAULT_DAYS = 30

module CleanupRefinement
  refine Pathname do
    def incomplete?
      extname.end_with?(".incomplete")
    end

    def nested_cache?
      directory? && %w[
        cargo_cache
        go_cache
        go_mod_cache
        glide_home
        java_cache
        npm_cache
        gclient_cache
      ].include?(basename.to_s)
    end

    def go_cache_directory?
      # Go makes its cache contents read-only to ensure cache integrity,
      # which makes sense but is something we need to undo for cleanup.
      directory? && %w[go_cache go_mod_cache].include?(basename.to_s)
    end

    def prune?(days)
      return false unless days
      return true if days.zero?

      return true if symlink? && !exist?

      mtime < days.days.ago && ctime < days.days.ago
    end

    def stale?(scrub = false)
      return false unless resolved_path.file?

      if dirname.basename.to_s == "Cask"
        stale_cask?(scrub)
{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.00186219739292365, 'mean_word_length': 2.872072072072072, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857653', 'n_tokens_mistral': 705, 'n_tokens_neox': 686, 'n_words': 189}