Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        // 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();
        }