Class: Beni::Vendor::Tarball

Inherits:
Object
  • Object
show all
Defined in:
lib/beni/vendor/tarball.rb

Overview

Unpacks a vendored tarball into final_dir, idempotent on a .beni-version marker stamped inside the tree. One instance per (tarball, top_level_dir, final_dir, version) configuration; reuse is not supported and not needed by Beni::Tasks.

A version mismatch (toolchain bump) forces a clean re-extract, so the unpacked tree never lags the pinned version. Public contract is the single #prepare entry point; the staging-directory step is internal.

Constant Summary collapse

VERSION_MARKER =

Marker stamped inside final_dir after a successful unpack; a matching value short-circuits #prepare, a mismatch forces re-extract.

".beni-version"

Instance Method Summary collapse

Constructor Details

#initialize(tarball:, top_level_dir:, final_dir:, version:) ⇒ Tarball

Returns a new instance of Tarball.



20
21
22
23
24
25
# File 'lib/beni/vendor/tarball.rb', line 20

def initialize(tarball:, top_level_dir:, final_dir:, version:)
  @tarball = tarball
  @top_level_dir = top_level_dir
  @final_dir = final_dir
  @version = version
end

Instance Method Details

#prepareObject

Extract the tarball into a staging sibling of final_dir, then atomically move the top_level_dir subtree into place and stamp the version marker. A no-op when the stamped version already matches. Raises if the tarball does not contain the expected top_level_dir root. The staging tree is removed whether or not extraction succeeds.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/beni/vendor/tarball.rb', line 32

def prepare
  return if installed_version == @version

  staging = "#{@final_dir}.staging"
  begin
    extract_to_staging(staging)
    promote(staging)
  ensure
    FileUtils.rm_rf(staging)
  end
end