Sha256: a42301aa865172cf0c34dabab24affa9085fa7d9696b5bafa562cdbf9434ad14

Contents?: true

Size: 673 Bytes

Versions: 2

Compression:

Stored size: 673 Bytes

Contents

class KuberKit::Tools::BuildDirCleaner
  include KuberKit::Import[
    "shell.bash_commands",
  ]

  KEEP_DIRS_COUNT = 10

  Contract KuberKit::Shell::AbstractShell, KeywordArgs[parent_dir: String] => Any
  def call(shell, parent_dir:)
    dirs_to_delete = get_ancient_builds_dirs(shell, parent_dir: parent_dir)

    dirs_to_delete.each do |dir|
      bash_commands.rm_rf(shell, dir)
    end
  end

  private
    def get_ancient_builds_dirs(shell, parent_dir:)
      all_dirs  = shell.list_dirs("#{parent_dir}/*")

      skip_dirs = all_dirs
        .sort_by{ |f| bash_commands.ctime(shell, f) }
        .reverse[0...KEEP_DIRS_COUNT]

      all_dirs - skip_dirs
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kuber_kit-0.9.6 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-0.9.5 lib/kuber_kit/tools/build_dir_cleaner.rb