class Longleaf::PreserveCommand

Command for preserving files

Public Class Methods

new(app_manager) click to toggle source
# File lib/longleaf/commands/preserve_command.rb, line 16
def initialize(app_manager)
  @app_manager = app_manager
end

Public Instance Methods

execute(file_selector:, force: false) click to toggle source

Execute the preserve command on the given parameters @param file_selector [FileSelector] selector for files to preserve @param force [Boolean] force flag @return [Integer] status code

# 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