Sha256: 26e006102fbdc5685bb1b0cd543e73a9aa9ed8449eb8adb876c6f07a1653bf7c

Contents?: true

Size: 985 Bytes

Versions: 17

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Int::Compiler::Stages
  class Cleanup
    def initialize(config)
      @config = config
    end

    def run
      cleanup_temps(Nanoc::Filter::TMP_BINARY_ITEMS_DIR)
      cleanup_temps(Nanoc::Int::ItemRepWriter::TMP_TEXT_ITEMS_DIR)
      cleanup_unused_stores
      cleanup_old_stores
    end

    private

    def cleanup_temps(dir)
      Nanoc::Int::TempFilenameFactory.instance.cleanup(dir)
    end

    def cleanup_unused_stores
      used_paths = @config.output_dirs.map { |d| Nanoc::Int::Store.tmp_path_prefix(d) }
      all_paths = Dir.glob('tmp/nanoc/*')
      (all_paths - used_paths).each do |obsolete_path|
        FileUtils.rm_rf(obsolete_path)
      end
    end

    def cleanup_old_stores
      %w[checksums compiled_content dependencies outdatedness action_sequence].each do |fn|
        full_fn = File.join('tmp', fn)
        if File.file?(full_fn)
          FileUtils.rm_f(full_fn)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
nanoc-4.8.11 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.10 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.9 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.8 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.7 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.6 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.5 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.4 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.3 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.2 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.1 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.8.0 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.7.14 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.7.13 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.7.12 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.7.11 lib/nanoc/base/services/compiler/stages/cleanup.rb
nanoc-4.7.10 lib/nanoc/base/services/compiler/stages/cleanup.rb