lib/nanoc/base/services/compiler.rb in nanoc-4.5.4 vs lib/nanoc/base/services/compiler.rb in nanoc-4.6.0
- old
+ new
@@ -345,10 +345,36 @@
mark_done_phase
end
end
end
+
+ 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
+ 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
+ end
end
include Nanoc::Int::ContractsSupport
# @api private
@@ -407,16 +433,11 @@
store
compile_reps
store_output_state
@action_provider.postprocess(@site, @reps)
ensure
- Nanoc::Int::TempFilenameFactory.instance.cleanup(
- Nanoc::Filter::TMP_BINARY_ITEMS_DIR,
- )
- Nanoc::Int::TempFilenameFactory.instance.cleanup(
- Nanoc::Int::ItemRepWriter::TMP_TEXT_ITEMS_DIR,
- )
+ cleanup_stage.run
end
def load_stores
stores.each(&:load)
end
@@ -491,9 +512,13 @@
dependency_store: @dependency_store,
action_provider: action_provider,
compilation_context: compilation_context,
compiled_content_cache: compiled_content_cache,
)
+ end
+
+ def cleanup_stage
+ @_cleanup_stage ||= Stages::Cleanup.new(site.config)
end
def determine_outdatedness
determine_outdatedness_stage.run do |outdated_items|
@outdated_items = outdated_items