Class: Longleaf::PreserveCommand

Inherits:
Object
  • Object
show all
Includes:
EventStatusTracking, Logging
Defined in:
lib/longleaf/commands/preserve_command.rb

Overview

Command for preserving files

Instance Method Summary collapse

Methods included from EventStatusTracking

#record_failure, #record_success, #return_status, #track_failure, #track_status, #track_success

Methods included from Logging

#initialize_logger, initialize_logger, logger, #logger

Constructor Details

#initialize(app_manager) ⇒ PreserveCommand

Returns a new instance of PreserveCommand.



16
17
18
# File 'lib/longleaf/commands/preserve_command.rb', line 16

def initialize(app_manager)
  @app_manager = app_manager
end

Instance Method Details

#execute(file_selector:, force: false) ⇒ Integer

Execute the preserve command on the given parameters

Parameters:

  • file_selector (FileSelector)

    selector for files to preserve

  • force (Boolean) (defaults to: false)

    force flag

Returns:

  • (Integer)

    status code



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/longleaf/commands/preserve_command.rb', line 24

def execute(file_selector:, force: false)
  start_time = Time.now
  logger.info('Performing preserve command')
  begin
    # Perform preserve events on each of the file paths provided
    candidate_locator = ServiceCandidateLocator.new(@app_manager)
    candidate_it = candidate_locator.candidate_iterator(file_selector, EventNames::PRESERVE, force)
    candidate_it.each do |file_rec|
      begin
        logger.debug("Selected candidate #{file_rec.path} for a preserve event")
        preserve_event = PreserveEvent.new(file_rec: file_rec, force: force, app_manager: @app_manager)
        track_status(preserve_event.perform)
      rescue InvalidStoragePathError => e
        record_failure(EventNames::PRESERVE, nil, e.message)
      end
    end
  rescue LongleafError => e
    record_failure(EventNames::PRESERVE, nil, e.message)
  rescue => err
    record_failure(EventNames::PRESERVE, error: err)
  end

  logger.info("Completed preserve command in #{Time.now - start_time}s")
  return_status
end