Class: Tebako::FilesystemCache
- Inherits:
-
Object
- Object
- Tebako::FilesystemCache
- Defined in:
- lib/tebako/filesystem_cache.rb
Overview
Stores complete DwarFS images by the content and options that produced them.
Instance Method Summary collapse
-
#fetch(output) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(cache_dir:, mkdwarfs:, source_dir:, descriptor:, compression_level:) ⇒ FilesystemCache
constructor
A new instance of FilesystemCache.
Constructor Details
#initialize(cache_dir:, mkdwarfs:, source_dir:, descriptor:, compression_level:) ⇒ FilesystemCache
Returns a new instance of FilesystemCache.
39 40 41 42 43 44 45 |
# File 'lib/tebako/filesystem_cache.rb', line 39 def initialize(cache_dir:, mkdwarfs:, source_dir:, descriptor:, compression_level:) @cache_dir = cache_dir @mkdwarfs = mkdwarfs @source_dir = source_dir @descriptor = descriptor @compression_level = compression_level end |
Instance Method Details
#fetch(output) ⇒ Object
rubocop:disable Metrics/MethodLength
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tebako/filesystem_cache.rb', line 47 def fetch(output) # rubocop:disable Metrics/MethodLength FileUtils.mkdir_p(@cache_dir) key = cache_key cache_path = File.join(@cache_dir, "#{key}.dwarfs") started_at = monotonic_time File.open("#{cache_path}.lock", File::RDWR | File::CREAT, 0o644) do |lock| lock.flock(File::LOCK_EX) if restore?(cache_path, output) report("reused", "filesystem inputs and compression options are unchanged", key, started_at) next end FileUtils.rm_f([cache_path, (cache_path)]) yield save(cache_path, output) report("rebuilt", "no matching packaged filesystem exists", key, started_at) end end |