You are here

function s3_delete in Filebrowser 7.4

Same name and namespace in other branches
  1. 7.3 modules/s3_fb.module \s3_delete()
1 call to s3_delete()
filebrowser_form_delete_confirm_submit in ./filebrowser.module
File delete confirmation form submit

File

modules/s3_fb.module, line 93

Code

function s3_delete($target) {
  $client = awssdk_get_client('s3');
  $client
    ->registerStreamWrapper();
  $type = filetype($target);
  switch ($type) {
    case "file":
      $result = unlink($target);
      if (!$result) {
        drupal_set_message(t('Unable to delete @file', array(
          '@file' => $target,
        )), 'warning');
      }
      break;
    case "dir":

      // todo: s3 will not delete an non-empty folder. But wil fail silently.
      // todo: check why we need an end slash
      $result = $client
        ->deleteObject(s3_object_info($target . '/'));
      if (!$result) {
        drupal_set_message(t('Unable to delete @file', array(
          '@file' => $target,
        )), 'warning');
      }
      break;
    default:
      drupal_set_message(t('Switch case default error in function s3_delete().'), 'error');
  }
}