Class: Dor::CleanupResetService
- Inherits:
-
Object
- Object
- Dor::CleanupResetService
- Defined in:
- lib/dor/services/cleanup_reset_service.rb
Overview
Remove all traces of the object’s data files from the workspace and export areas
Class Method Summary collapse
-
.cleanup_assembly_content(druid, base) ⇒ void
Remove the object’s data files from the assembly area.
-
.cleanup_by_reset_druid(druid) ⇒ void
Remove copy of the reset data that was exported to preservation core.
-
.cleanup_reset_export(druid, last_version) ⇒ void
Remove copy of the reset data that was exported to preservation core.
-
.cleanup_reset_workspace_content(druid, last_version, base) ⇒ void
Remove all the object’s reset data files from the workspace area equal to less than the last_version.
- .get_druid_last_version(druid) ⇒ Object
-
.get_reset_bag_dir_list(last_version, base_bag_directory) ⇒ void
Prepares a list of reset bag directories that should be removed.
-
.get_reset_bag_tar_list(last_version, base_bag_directory) ⇒ void
Prepares a list of reset bag tars that should be removed.
-
.get_reset_dir_list(last_version, base_druid_tree) ⇒ void
Prepares a list of reset directories that should be removed.
Class Method Details
.cleanup_assembly_content(druid, base) ⇒ void
100 101 102 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 100 def self.cleanup_assembly_content(druid, base) DruidTools::Druid.new(druid, base).prune! end |
.cleanup_by_reset_druid(druid) ⇒ void
9 10 11 12 13 14 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 9 def self.cleanup_by_reset_druid(druid) last_version = get_druid_last_version(druid) cleanup_reset_workspace_content(druid, last_version, Config.cleanup.local_workspace_root) cleanup_assembly_content(druid, Config.cleanup.local_assembly_root) cleanup_reset_export(druid, last_version) end |
.cleanup_reset_export(druid, last_version) ⇒ void
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 58 def self.cleanup_reset_export(druid, last_version) id = druid.split(':').last base_bag_directory = File.join(Config.cleanup.local_export_home, id) bag_dir_list = get_reset_bag_dir_list(last_version, base_bag_directory) bag_dir_list.each do |bag_dir| Pathname(bag_dir).rmtree end bag_tar_list = get_reset_bag_tar_list(last_version, base_bag_directory) bag_tar_list.each do |bag_tar| Pathname(bag_tar).rmtree end end |
.cleanup_reset_workspace_content(druid, last_version, base) ⇒ void
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 31 def self.cleanup_reset_workspace_content(druid, last_version, base) base_druid = DruidTools::Druid.new(druid, base) base_druid_tree = base_druid.pathname.to_s # if it is truncated tree /aa/111/aaa/1111/content, # we should follow the regular cleanup technique reset_directories = get_reset_dir_list(last_version, base_druid_tree) reset_directories.each do |path| FileUtils.rm_rf(path) end base_druid.prune_ancestors(base_druid.pathname.parent) end |
.get_druid_last_version(druid) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 16 def self.get_druid_last_version(druid) druid_obj = Dor::Item.find(druid) last_version = druid_obj.current_version.to_i # if the current version is still open, avoid this versioned directory if Dor::Config.workflow.client.get_lifecycle('dor', druid, 'accessioned').nil? last_version -= 1 end last_version end |
.get_reset_bag_dir_list(last_version, base_bag_directory) ⇒ void
76 77 78 79 80 81 82 83 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 76 def self.get_reset_bag_dir_list(last_version, base_bag_directory) reset_bags = [] (1..last_version).each do |i| reset_path = "#{base_bag_directory}_v#{i}" reset_bags.append(reset_path) if File.exist?(reset_path) end reset_bags end |
.get_reset_bag_tar_list(last_version, base_bag_directory) ⇒ void
88 89 90 91 92 93 94 95 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 88 def self.get_reset_bag_tar_list(last_version, base_bag_directory) reset_bags = [] (1..last_version).each do |i| reset_path = "#{base_bag_directory}_v#{i}.tar" reset_bags.append(reset_path) if File.exist?(reset_path) end reset_bags end |
.get_reset_dir_list(last_version, base_druid_tree) ⇒ void
47 48 49 50 51 52 53 54 |
# File 'lib/dor/services/cleanup_reset_service.rb', line 47 def self.get_reset_dir_list(last_version, base_druid_tree) reset_directories = [] (1..last_version).each do |i| reset_path = "#{base_druid_tree}_v#{i}" reset_directories.append(reset_path) if File.exist?(reset_path) end reset_directories end |