Skip to content

Make it easier to delete buckets with versioned objects #152

@MarkEdmondson1234

Description

@MarkEdmondson1234

It won't let you delete the bucket if a versioned object still in there. a few hoops to go through to delete them too

gcp_gcs_delete_bucket <- function(bucket){
  # have to delete all objects in a bucket first
  os <- googleCloudStorageR::gcs_list_objects(bucket, 
                                              versions = TRUE, 
                                              detail = "full")
  safe_delete <- function(x, bucket, version = NULL){
    tryCatch({
      googleCloudStorageR::gcs_delete_object(x, 
                                             bucket = bucket,
                                             generation = version)
    }, error = function(ex) {
      NULL
    })
  }
  
  lapply(os$name, safe_delete, bucket = bucket)
  mapply(safe_delete, 
         x = os$name, version = os$generation, 
         MoreArgs = list(bucket = bucket))
  bb <- googleCloudStorageR::gcs_get_bucket(bucket)
  googleCloudStorageR::gcs_delete_bucket(bb$name)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions