Class: Longleaf::FileCheckService

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/longleaf/preservation_services/file_check_service.rb

Overview

Preservation service which validates a file using current filesystem information compared against the last registered details for that file. Checks using file name, size and last modified timestamp.

Instance Method Summary collapse

Methods included from Logging

#initialize_logger, initialize_logger, logger, #logger

Constructor Details

#initialize(service_def, app_manager) ⇒ FileCheckService

Initialize a FileCheckService from the given service definition

Parameters:

  • the configuration for this service

  • manager for configured storage locations



14
15
16
17
# File 'lib/longleaf/preservation_services/file_check_service.rb', line 14

def initialize(service_def, app_manager)
  @service_def = service_def
  @app_manager = app_manager
end

Instance Method Details

#is_applicable?(event) ⇒ Boolean

Determine if this service is applicable for the provided event, given the configured service definition

Parameters:

  • name of the event

Returns:

  • returns true if this service is applicable for the provided event



50
51
52
53
54
55
56
57
# File 'lib/longleaf/preservation_services/file_check_service.rb', line 50

def is_applicable?(event)
  case event
  when EventNames::PRESERVE
    true
  else
    false
  end
end

#perform(file_rec, event) ⇒ Object

Perform file information check.

Parameters:

  • record representing the file to perform the service on.

  • name of the event this service is being invoked by.

Raises:

  • if the file system information does not match the stored details



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/longleaf/preservation_services/file_check_service.rb', line 24

def perform(file_rec, event)
  file_path = file_rec.path
  phys_path = file_rec.physical_path
  md_rec = file_rec.

  logger.debug("Performing file information check of #{file_path}")

  if !File.exist?(phys_path)
    raise PreservationServiceError.new("File does not exist: #{phys_path}")
  end

  file_size = File.size(phys_path)
  if file_size != md_rec.file_size
    raise PreservationServiceError.new("File size for #{phys_path} does not match the expected value: registered = #{md_rec.file_size} bytes, actual = #{file_size} bytes")
  end

  last_modified = File.mtime(phys_path).utc.iso8601(3)
  if last_modified != md_rec.last_modified
    raise PreservationServiceError.new("Last modified timestamp for #{phys_path} does not match the expected value: registered = #{md_rec.last_modified}, actual = #{last_modified}")
  end
end