Class: Longleaf::FileCheckService
- Inherits:
-
Object
- Object
- Longleaf::FileCheckService
- 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
-
#initialize(service_def, app_manager) ⇒ FileCheckService
constructor
Initialize a FileCheckService from the given service definition.
-
#is_applicable?(event) ⇒ Boolean
Determine if this service is applicable for the provided event, given the configured service definition.
-
#perform(file_rec, event) ⇒ Object
Perform file information check.
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
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
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.
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 |