Class: Dor::CleanupService

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/cleanup_service.rb

Overview

Remove all traces of the object’s data files from the workspace and export areas

Class Method Summary collapse

Class Method Details

.cleanup(dor_item) ⇒ void

This method returns an undefined value.

Returns Delete all workspace and export entities for the druid.

Parameters:

  • dor_item (LyberCore::Robots::WorkItem)

    The DOR work item whose workspace should be cleaned up



10
11
12
13
# File 'lib/dor/services/cleanup_service.rb', line 10

def self.cleanup(dor_item)
  druid = dor_item.druid
  cleanup_by_druid druid
end

.cleanup_by_druid(druid) ⇒ Object



15
16
17
18
19
# File 'lib/dor/services/cleanup_service.rb', line 15

def self.cleanup_by_druid(druid)
  cleanup_workspace_content(druid, Config.cleanup.local_workspace_root)
  cleanup_workspace_content(druid, Config.cleanup.local_assembly_root)
  cleanup_export(druid)
end

.cleanup_export(druid) ⇒ void

This method returns an undefined value.

Returns remove copy of the data that was exported to preservation core.

Parameters:

  • druid (String)

    The identifier for the object whose data is to be removed



30
31
32
33
34
35
36
# File 'lib/dor/services/cleanup_service.rb', line 30

def self.cleanup_export(druid)
  id = druid.split(':').last
  bag_dir = File.join(Config.cleanup.local_export_home, id)
  self.remove_branch(bag_dir)
  tarfile = "#{bag_dir}.tar"
  self.remove_branch(tarfile)
end

.cleanup_workspace_content(druid, base) ⇒ void

This method returns an undefined value.

Returns remove the object’s data files from the workspace area.

Parameters:

  • druid (String)

    The identifier for the object whose data is to be removed

  • base (String)

    The base directory to delete from



24
25
26
# File 'lib/dor/services/cleanup_service.rb', line 24

def self.cleanup_workspace_content(druid, base)
  DruidTools::Druid.new(druid, base).prune!
end

.remove_branch(pathname) ⇒ void

This method returns an undefined value.

Returns Remove the specified directory and all its children.

Parameters:

  • pathname (Pathname, String)

    The full path of the branch to be removed



40
41
42
43
# File 'lib/dor/services/cleanup_service.rb', line 40

def self.remove_branch(pathname)
  pathname = Pathname(pathname) if pathname.instance_of? String
  pathname.rmtree if pathname.exist?
end