Class: OsCtld::SendReceive::Commands::Cleanup

Inherits:
Base show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Utils::Receive
Defined in:
lib/osctld/send_receive/commands/receive_cancel.rb

Instance Attribute Summary

Attributes inherited from Commands::Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods included from Utils::Receive

#check_auth_pubkey, #receive_pipeline_error

Methods inherited from Base

#base_execute, handle, #receive_pipeline_error, #validate_protocol_version!, #validate_send_log_protocol!

Methods inherited from Commands::Base

#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

Instance Method Details

#executeObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/osctld/send_receive/commands/receive_cancel.rb', line 52

def execute
  ct = SendReceive::Tokens.find_container(opts[:token])
  error!('container not found') unless ct
  error!('the pool is disabled') unless ct.pool.active?

  ct.manipulate(self, block: true) do
    if !ct.send_log || !ct.send_log.can_receive_continue?(:cleanup)
      error!('invalid send sequence')
    elsif !check_auth_pubkey(opts[:key_pool], opts[:key_name], ct)
      error!('authentication key mismatch')
    end

    validate_send_log_protocol!(ct)

    ct.exclusively do
      ct.send_log.state = :cleanup
      ct.save_config
    end

    ct.send_log.snapshots.each do |ds, snap|
      zfs(:destroy, nil, "#{ds}@#{snap}", valid_rcs: [1])
    end

    SendReceive.stopped_using_key(ct.pool, ct.send_log.opts.key_name)
    ct.close_send_log
  end

  ok
end