class ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject < ::CloudObjectStoreObject
  supports :delete do
    unless ext_management_system
      unsupported_reason_add(:delete, _("The Storage Object is not connected to an active %{table}") % {
        :table => ui_lookup(:table => "ext_management_systems")
      })
    end

    unless cloud_object_store_container
      unsupported_reason_add(:delete, _("The Storage Object is not connected to an active %{table}") % {
        :table => ui_lookup(:table => "cloud_object_store_containers")
      })
    end
  end

  def provider_object(connection = nil)
    cloud_object_store_container.provider_object(connection).object(key)
  end

  def raw_delete
    with_provider_object(&:delete)
  end
end

class ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject < ::CloudObjectStoreObject
  supports :delete do
    unless ext_management_system
      unsupported_reason_add(:delete, _("The Storage Object is not connected to an active %{table}") % {
        :table => ui_lookup(:table => "ext_management_systems")
      })
    end

    unless cloud_object_store_container
      unsupported_reason_add(:delete, _("The Storage Object is not connected to an active %{table}") % {
        :table => ui_lookup(:table => "cloud_object_store_containers")
      })
    end
  end

  def provider_object(connection = nil)
    cloud_object_store_container.provider_object(connection).object(key)
  end

  def raw_delete
    if key.end_with? "/" # delete object with subobjects (aka. folder)
      cloud_object_store_container.provider_object.objects(:prefix => key).batch_delete!
    else # delete single object
      with_provider_object(&:delete)
    end
  end
end

Support deletion of S3 folders
Support deletion of S3 folders

On S3 folders are nothing but regular objects. However, deleting
folder fails silently if there are any objects in it. To resolve
this issue, we perform a batch delete of all objects within that
folder.

BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1444079

Signed-off-by: Miha Pleško <e42a14dbca5c0965023849a10306da025a317640@xlab.si>
