module Fiona7 module BinaryFilesCleaner def delete_unused(binary) perform_with_unused(binary, "delete!") end def unrelease_unused(binary) perform_with_unused(binary, "unrelease!") end private def perform_with_unused(binary, action) blob_objs = Fiona7::WriteObj.where(obj_class: binary.obj_class, parent_obj_id: binary.parent_obj_id) blob_objs.each do |blob_obj| Rails.logger.info("Checking binary obj #{blob_obj.obj_id}") if (!blob_obj.has_super_links? && blob_obj.obj_id != binary.obj_id) # perform delete! without to check released? if action == "delete!" || blob_obj.released? Rails.logger.info("#{action} binary obj #{blob_obj.obj_id}") Reactor::Sudo.su(Fiona7.root) do blob_obj.send(:crul_obj).send(action) end end end end end end end