diff --git a/task/aws/resources/resource_bucket.go b/task/aws/resources/resource_bucket.go index 76e56722..12025fda 100644 --- a/task/aws/resources/resource_bucket.go +++ b/task/aws/resources/resource_bucket.go @@ -78,54 +78,17 @@ func (b *Bucket) Update(ctx context.Context) error { } func (b *Bucket) Delete(ctx context.Context) error { - listInput := s3.ListObjectsV2Input{ + input := s3.DeleteBucketInput{ Bucket: aws.String(b.Identifier), } - for paginator := s3.NewListObjectsV2Paginator(b.Client.Services.S3, &listInput); paginator.HasMorePages(); { - page, err := paginator.NextPage(ctx) - - if err != nil { - var e smithy.APIError - if errors.As(err, &e) && e.ErrorCode() == "NoSuchBucket" { - b.Resource = nil - return nil - } - return err - } - - if len(page.Contents) == 0 { - break - } - - var objects []types.ObjectIdentifier - for _, object := range page.Contents { - objects = append(objects, types.ObjectIdentifier{ - Key: object.Key, - }) - } - - input := s3.DeleteObjectsInput{ - Bucket: aws.String(b.Identifier), - Delete: &types.Delete{ - Objects: objects, - }, - } - - if _, err = b.Client.Services.S3.DeleteObjects(ctx, &input); err != nil { + if _, err := b.Client.Services.S3.DeleteBucket(ctx, &input); err != nil { + var e smithy.APIError + if errors.As(err, &e) && e.ErrorCode() != "NoSuchBucket" { return err } } - deleteInput := s3.DeleteBucketInput{ - Bucket: aws.String(b.Identifier), - } - - _, err := b.Client.Services.S3.DeleteBucket(ctx, &deleteInput) - if err != nil { - return err - } - b.Resource = nil return nil } diff --git a/task/aws/task.go b/task/aws/task.go index 29c52765..321200da 100644 --- a/task/aws/task.go +++ b/task/aws/task.go @@ -192,7 +192,7 @@ func (t *Task) Read(ctx context.Context) error { func (t *Task) Delete(ctx context.Context) error { logrus.Info("[1/8] Downloading Directory...") - if t.Read(ctx) == nil { + if t.Resources.Bucket.Read(ctx) == nil { if t.Attributes.Environment.DirectoryOut != "" { if err := t.Pull(ctx, t.Attributes.Environment.Directory, t.Attributes.Environment.DirectoryOut); err != nil && err != common.NotFoundError { return err diff --git a/task/az/task.go b/task/az/task.go index 4b5d97a6..fe6037e3 100644 --- a/task/az/task.go +++ b/task/az/task.go @@ -185,7 +185,7 @@ func (t *Task) Read(ctx context.Context) error { func (t *Task) Delete(ctx context.Context) error { logrus.Info("[1/9] Downloading Directory...") - if t.Read(ctx) == nil { + if t.Resources.BlobContainer.Read(ctx) == nil { if t.Attributes.Environment.DirectoryOut != "" { if err := t.Pull(ctx, t.Attributes.Environment.Directory, t.Attributes.Environment.DirectoryOut); err != nil && err != common.NotFoundError { return err diff --git a/task/common/machine/storage.go b/task/common/machine/storage.go index 91cea474..7122e0ee 100644 --- a/task/common/machine/storage.go +++ b/task/common/machine/storage.go @@ -142,6 +142,22 @@ func Delete(ctx context.Context, destination string) error { return err } + ctx, fi := filter.AddConfig(ctx) + if err := fi.AddRule("+ **"); err != nil { + return err + } + + operations.SyncPrintf = func(format string, a ...interface{}) { + logrus.Infof(format, a...) + } + fs.LogPrint = func(level fs.LogLevel, text string) { + logrus.Info(text) + } + + ctx, ci := fs.AddConfig(ctx) + ci.LogLevel = fs.LogLevelDebug + ci.StatsLogLevel = fs.LogLevelDebug + actions := []func(context.Context) error{ func(ctx context.Context) error { return operations.Delete(ctx, destinationFileSystem) diff --git a/task/gcp/resources/resource_bucket.go b/task/gcp/resources/resource_bucket.go index b7c23b79..8d9d017b 100644 --- a/task/gcp/resources/resource_bucket.go +++ b/task/gcp/resources/resource_bucket.go @@ -61,25 +61,11 @@ func (b *Bucket) Update(ctx context.Context) error { } func (b *Bucket) Delete(ctx context.Context) error { - if b.Read(ctx) == common.NotFoundError { - return nil - } - - deletePage := func(objects *storage.Objects) error { - for _, object := range objects.Items { - if err := b.Client.Services.Storage.Objects.Delete(b.Identifier, object.Name).Do(); err != nil { - return err - } - } - return nil - } - - if err := b.Client.Services.Storage.Objects.List(b.Identifier).Pages(ctx, deletePage); err != nil { - return err - } - if err := b.Client.Services.Storage.Buckets.Delete(b.Identifier).Do(); err != nil { - return err + var e *googleapi.Error + if errors.As(err, &e) && e.Code != 404 { + return err + } } b.Resource = nil diff --git a/task/gcp/task.go b/task/gcp/task.go index 26b3f682..9d516cf1 100644 --- a/task/gcp/task.go +++ b/task/gcp/task.go @@ -263,8 +263,8 @@ func (t *Task) Read(ctx context.Context) error { } func (t *Task) Delete(ctx context.Context) error { - logrus.Info("[1/11] Downloading Directory...") - if t.Read(ctx) == nil { + logrus.Debug("[1/11] Downloading Directory...") + if t.Resources.Bucket.Read(ctx) == nil { if t.Attributes.Environment.DirectoryOut != "" { if err := t.Pull(ctx, t.Attributes.Environment.Directory, t.Attributes.Environment.DirectoryOut); err != nil && err != common.NotFoundError { return err