mirror of
https://github.com/minio/minio.git
synced 2025-11-25 03:56:17 -05:00
add force delete option of non-empty bucket (#9166)
passing HTTP header `x-minio-force-delete: true` would allow standard S3 API DeleteBucket to delete a non-empty bucket forcefully.
This commit is contained in:
@@ -326,7 +326,7 @@ func undoMakeBucketZones(bucket string, zones []*xlSets, errs []error) {
|
||||
index := index
|
||||
g.Go(func() error {
|
||||
if errs[index] == nil {
|
||||
return zones[index].DeleteBucket(context.Background(), bucket)
|
||||
return zones[index].DeleteBucket(context.Background(), bucket, false)
|
||||
}
|
||||
return nil
|
||||
}, index)
|
||||
@@ -1232,9 +1232,9 @@ func (z *xlZones) IsCompressionSupported() bool {
|
||||
// DeleteBucket - deletes a bucket on all zones simultaneously,
|
||||
// even if one of the zones fail to delete buckets, we proceed to
|
||||
// undo a successful operation.
|
||||
func (z *xlZones) DeleteBucket(ctx context.Context, bucket string) error {
|
||||
func (z *xlZones) DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error {
|
||||
if z.SingleZone() {
|
||||
return z.zones[0].DeleteBucket(ctx, bucket)
|
||||
return z.zones[0].DeleteBucket(ctx, bucket, forceDelete)
|
||||
}
|
||||
g := errgroup.WithNErrs(len(z.zones))
|
||||
|
||||
@@ -1242,11 +1242,26 @@ func (z *xlZones) DeleteBucket(ctx context.Context, bucket string) error {
|
||||
for index := range z.zones {
|
||||
index := index
|
||||
g.Go(func() error {
|
||||
return z.zones[index].DeleteBucket(ctx, bucket)
|
||||
return z.zones[index].DeleteBucket(ctx, bucket, forceDelete)
|
||||
}, index)
|
||||
}
|
||||
|
||||
errs := g.Wait()
|
||||
|
||||
if forceDelete {
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
if _, ok := err.(InsufficientWriteQuorum); ok {
|
||||
undoDeleteBucketZones(bucket, z.zones, errs)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// For any write quorum failure, we undo all the delete buckets operation
|
||||
// by creating all the buckets again.
|
||||
for _, err := range errs {
|
||||
|
||||
Reference in New Issue
Block a user