Class: ConfCtl::NixCollectGarbage

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/nix_collect_garbage.rb

Overview

Run nix-collect-garbage on Machine

Defined Under Namespace

Classes: Progress

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ NixCollectGarbage

Returns a new instance of NixCollectGarbage.

Parameters:

  • machine (String)


32
33
34
# File 'lib/confctl/nix_collect_garbage.rb', line 32

def initialize(machine)
  @machine = machine
end

Instance Method Details

#run! {|progress| ... } ⇒ TTY::Command::Result

Yield Parameters:

Returns:

  • (TTY::Command::Result)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/confctl/nix_collect_garbage.rb', line 38

def run!
  mc = MachineControl.new(machine)

  line_buf = StdLineBuffer.new do |out, err|
    next unless block_given?

    # %d store paths deleted, %f MiB freed
    yield(Progress.new(out)) if out

    # finding garbage collector roots...
    # removing stale link from '...'
    # deleting garbage...
    # deleting '/nix/store/...'
    # ...
    yield(Progress.new(err)) if err
  end

  ret = mc.execute!('nix-collect-garbage', &line_buf.feed_block)
  line_buf.flush
  ret
end