Sha256: c21e8223e79669a9c53a3e871d846c5a846616e15a2ae5bc12cdf85573c8d7dc
Contents?: true
Size: 849 Bytes
Versions: 20
Compression:
Stored size: 849 Bytes
Contents
require 'uri' module Ddr::Datastreams class DeleteExternalFiles def self.call(*args) event = ActiveSupport::Notifications::Event.new(*args) case event.name when Ddr::Datastreams::DELETE delete_files(event.payload[:version_history]) when Ddr::Models::Base::DELETE, Ddr::Models::Base::DEACCESSION delete_files(event.payload[:datastream_history].values.flatten) end end def self.get_files_to_delete(profiles) return [] if profiles.empty? profiles .select { |prof| (prof["dsControlGroup"] == "E") && prof["dsLocation"].start_with?("file:") } .map { |prof| Ddr::Utils.path_from_uri(prof["dsLocation"]) } end def self.delete_files(profiles) paths = get_files_to_delete(profiles) FileUtils.rm_f(paths) unless paths.empty? end end end
Version data entries
20 entries across 20 versions & 1 rubygems