Sha256: 67349cc7a9c9806181848d837fc3079c61aaf1bed6494a1d458f765cf1348317

Contents?: true

Size: 952 Bytes

Versions: 28

Compression:

Stored size: 952 Bytes

Contents

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

  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)
    rescue KuberKit::Shell::AbstractShell::ShellError => e
      ui.print_debug "BuildDirCleaner", "Error while removing directory: #{e.inspect}"
    end
  rescue KuberKit::Shell::AbstractShell::DirNotFoundError
    ui.print_debug "BuildDirCleaner", "Build directory not found"
  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

28 entries across 28 versions & 1 rubygems

Version Path
kuber_kit-1.3.9 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.8 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.7 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.1.8 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.6 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.1.7 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.5 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.4 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.1.6 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.3 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.2 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.1.5 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.1 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.3.0 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.1.4 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.2.7 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.2.6 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.2.5 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.2.4 lib/kuber_kit/tools/build_dir_cleaner.rb
kuber_kit-1.2.2 lib/kuber_kit/tools/build_dir_cleaner.rb