private async Task DeleteBucketAsyncImpl(string bucket, DeleteBucketOptions options, CancellationToken cancellationToken) { var deleteBucketRequest = CreateDeleteBucketRequest(bucket, options); string userProject = options?.UserProject; if (options?.DeleteObjects ?? false) { // Don't start deleting objects if the bucket has the wrong metageneration to start with. var preconditionOptions = options.CreateGetBucketOptionsForPreconditions(); if (preconditionOptions != null) { await GetBucketAsync(bucket, preconditionOptions, cancellationToken).ConfigureAwait(false); } var objects = ListObjectsAsync(bucket, null, new ListObjectsOptions { Versions = true, UserProject = userProject }); using (var iterator = objects.GetEnumerator()) { while (await iterator.MoveNext(cancellationToken).ConfigureAwait(false)) { var obj = iterator.Current; var deleteObjectOptions = new DeleteObjectOptions { UserProject = userProject, Generation = obj.Generation }; await DeleteObjectAsync(obj, deleteObjectOptions, cancellationToken).ConfigureAwait(false); } } } await deleteBucketRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false); }
// Implementation methods assuming a previously-validate bucket name private void DeleteBucketImpl(string bucket, DeleteBucketOptions options) { // Create the request at the start, so we validate the options before we // start deleting objects. var deleteBucketRequest = CreateDeleteBucketRequest(bucket, options); string userProject = options?.UserProject; if (options?.DeleteObjects ?? false) { // Don't start deleting objects if the bucket has the wrong metageneration to start with. var preconditionOptions = options.CreateGetBucketOptionsForPreconditions(); if (preconditionOptions != null) { GetBucket(bucket, preconditionOptions); } foreach (var obj in ListObjects(bucket, null, new ListObjectsOptions { Versions = true, UserProject = userProject })) { var deleteObjectOptions = new DeleteObjectOptions { UserProject = userProject, Generation = obj.Generation }; DeleteObject(obj, deleteObjectOptions); } } deleteBucketRequest.Execute(); }
private ObjectsResource.DeleteRequest CreateDeleteObjectRequest(Object obj, DeleteObjectOptions options) { ValidateObject(obj, nameof(obj)); var request = Service.Objects.Delete(obj.Bucket, obj.Name); options?.ModifyRequest(request); return(request); }
/// <inheritdoc /> public override Task DeleteObjectAsync( string bucket, string objectName, DeleteObjectOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(CreateDeleteObjectRequest(bucket, objectName, options).ExecuteAsync(cancellationToken)); }
/// <summary> /// Deletes a version of the specified object asynchronously. /// </summary> /// <remarks> /// <para> /// By default this will delete the latest version of the object, but this can be /// controlled using <see cref="DeleteObjectOptions.Generation"/>. For buckets that support /// multiple versions, implicitly deleting the latest version only archives /// it so the object is still available and can be listed by specifying <see cref="ListObjectsOptions.Versions"/>. /// If the version is explicitly specified, the object is permanently deleted. /// </para> /// <para> /// If the bucket containing the object supports versioning, after this operation /// completes successfully there may still be another version of the same object. In buckets which /// do not support versioning, this operation will permanently delete the object. /// </para> /// <para> /// If the request attempts to delete an object that does not exist or a specific version that does /// not exist, this counts as a failure with an HTTP status code of 404. /// </para> /// </remarks> /// <param name="bucket">The name of the bucket containing the object. Must not be null.</param> /// <param name="objectName">The name of the object within the bucket. Must not be null.</param> /// <param name="options">Additional options for the operation. May be null, in which case appropriate /// defaults will be used.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>A task representing the asynchronous operation.</returns> public virtual Task DeleteObjectAsync( string bucket, string objectName, DeleteObjectOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
private ObjectsResource.DeleteRequest CreateDeleteObjectRequest(string bucket, string name, DeleteObjectOptions options) { ValidateBucketName(bucket); GaxPreconditions.CheckNotNull(name, nameof(name)); var request = Service.Objects.Delete(bucket, name); options?.ModifyRequest(request); return(request); }
/// <inheritdoc /> public override Task DeleteObjectAsync(Object obj, DeleteObjectOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(CreateDeleteObjectRequest(obj, options).ExecuteAsync(cancellationToken)); }
/// <inheritdoc /> public override void DeleteObject(Object obj, DeleteObjectOptions options = null) { CreateDeleteObjectRequest(obj, options).Execute(); }
/// <inheritdoc /> public override void DeleteObject(string bucket, string objectName, DeleteObjectOptions options = null) { CreateDeleteObjectRequest(bucket, objectName, options).Execute(); }
/// <summary> /// Deletes a version of the specified object synchronously. /// </summary> /// <remarks> /// <para> /// By default this will delete the latest version of the object, but this can be /// controlled using <see cref="DeleteObjectOptions.Generation"/>. For buckets that support /// multiple versions, implicitly deleting the latest version only archives /// it so the object is still available and can be listed by specifying <see cref="ListObjectsOptions.Versions"/>. /// If the version is explicitly specified, the object is permanently deleted. /// </para> /// <para> /// If the bucket containing the object supports versioning, after this operation /// completes successfully there may still be another version of the same object. In buckets which /// do not support versioning, this operation will permanently delete the object. /// </para> /// <para> /// If the request attempts to delete an object that does not exist or a specific version that does /// not exist, this counts as a failure with an HTTP status code of 404. /// </para> /// </remarks> /// <param name="bucket">The name of the bucket containing the object. Must not be null.</param> /// <param name="objectName">The name of the object within the bucket. Must not be null.</param> /// <param name="options">Additional options for the operation. May be null, in which case appropriate /// defaults will be used.</param> public virtual void DeleteObject(string bucket, string objectName, DeleteObjectOptions options = null) { throw new NotImplementedException(); }
/// <summary> /// Deletes a version of the specified object asynchronously. /// </summary> /// <remarks> /// <para> /// By default this will delete the latest version of the object, but this can be /// controlled using <see cref="DeleteObjectOptions.Generation"/>. Note that any generation information /// contained within <paramref name="obj"/> is ignored; the generation to delete is only controlled /// via <paramref name="options"/>. For buckets that support /// multiple versions, implicitly deleting the latest version only archives /// it so the object is still available and can be listed by specifying <see cref="ListObjectsOptions.Versions"/>. /// If the version is explicitly specified, the object is permanently deleted. /// </para> /// <para> /// If the bucket containing the object supports versioning, after this operation /// completes successfully there may still be another version of the same object. In buckets which /// do not support versioning, this operation will permanently delete the object. /// </para> /// <para> /// If the request attempts to delete an object that does not exist or a specific version that does /// not exist, this counts as a failure with an HTTP status code of 404. /// </para> /// </remarks> /// <param name="obj">Object to delete. Must not be null, and must have the name and bucket populated.</param> /// <param name="options">Additional options for the operation. May be null, in which case appropriate /// defaults will be used.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>A task representing the asynchronous operation.</returns> public virtual Task DeleteObjectAsync(Object obj, DeleteObjectOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
/// <summary> /// Deletes a version of the specified object synchronously. /// </summary> /// <remarks> /// <para> /// By default this will delete the latest version of the object, but this can be /// controlled using <see cref="DeleteObjectOptions.Generation"/>. Note that any generation information /// contained within <paramref name="obj"/> is ignored; the generation to delete is only controlled /// via <paramref name="options"/>. For buckets that support /// multiple versions, implicitly deleting the latest version only archives /// it so the object is still available and can be listed by specifying <see cref="ListObjectsOptions.Versions"/>. /// If the version is explicitly specified, the object is permanently deleted. /// </para> /// <para> /// If the bucket containing the object supports versioning, after this operation /// completes successfully there may still be another version of the same object. In buckets which /// do not support versioning, this operation will permanently delete the object. /// </para> /// <para> /// If the request attempts to delete an object that does not exist or a specific version that does /// not exist, this counts as a failure with an HTTP status code of 404. /// </para> /// </remarks> /// <param name="obj">Object to delete. Must not be null, and must have the name and bucket populated.</param> /// <param name="options">Additional options for the operation. May be null, in which case appropriate /// defaults will be used.</param> public virtual void DeleteObject(Object obj, DeleteObjectOptions options = null) { throw new NotImplementedException(); }