From b5c3cb98e56f0dc5c6e659d356045cf2d6ae44ee Mon Sep 17 00:00:00 2001 From: Dmitrii Neeman Date: Thu, 19 Sep 2024 16:30:25 +0300 Subject: [PATCH] FMWK-399-remove-artifacts-flag - ShouldClearTarget() --- cmd/internal/app/writers.go | 8 ++++---- cmd/internal/models/backup.go | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/internal/app/writers.go b/cmd/internal/app/writers.go index a1bf2dcc..92051dad 100644 --- a/cmd/internal/app/writers.go +++ b/cmd/internal/app/writers.go @@ -38,7 +38,7 @@ func newLocalWriter(ctx context.Context, b *models.Backup, c *models.Common) (ba opts = append(opts, local.WithFile(b.OutputFile)) } - if b.RemoveFiles || b.RemoveArtifacts { + if b.ShouldClearTarget() { opts = append(opts, local.WithRemoveFiles()) } @@ -72,7 +72,7 @@ func newS3Writer( opts = append(opts, s3.WithFile(path)) } - if b.RemoveFiles || b.RemoveArtifacts { + if b.ShouldClearTarget() { opts = append(opts, s3.WithRemoveFiles()) } @@ -102,7 +102,7 @@ func newGcpWriter( opts = append(opts, storage.WithFile(b.OutputFile)) } - if b.RemoveFiles || b.RemoveArtifacts { + if b.ShouldClearTarget() { opts = append(opts, storage.WithRemoveFiles()) } @@ -132,7 +132,7 @@ func newAzureWriter( opts = append(opts, blob.WithFile(b.OutputFile)) } - if b.RemoveFiles || b.RemoveArtifacts { + if b.ShouldClearTarget() { opts = append(opts, blob.WithRemoveFiles()) } diff --git a/cmd/internal/models/backup.go b/cmd/internal/models/backup.go index 8f6e26a0..08cd46f4 100644 --- a/cmd/internal/models/backup.go +++ b/cmd/internal/models/backup.go @@ -28,3 +28,8 @@ type Backup struct { ParallelNodes bool RemoveArtifacts bool } + +// ShouldClearTarget check if we should clean target directory. +func (b *Backup) ShouldClearTarget() bool { + return b.RemoveFiles || b.RemoveArtifacts +}