From eef679b3ee82699d601255d0b4448f6a39d69b3e Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 14 Feb 2024 11:58:14 +0100 Subject: [PATCH] fix: avoid using rm -rf for a regular file If dnsreport.sqlite3 isn't regular, then there's something deeply unexpected with the file system and we wouldn't want to zap something that may be precious to the user. --- internal/cmd/gardener/internal/dnsreport/dnsreport.go | 2 +- internal/cmd/gardener/internal/sync/sync.go | 2 +- internal/cmd/gardener/internal/sync/sync_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/cmd/gardener/internal/dnsreport/dnsreport.go b/internal/cmd/gardener/internal/dnsreport/dnsreport.go index ae980b7e8..d5edc649c 100644 --- a/internal/cmd/gardener/internal/dnsreport/dnsreport.go +++ b/internal/cmd/gardener/internal/dnsreport/dnsreport.go @@ -67,7 +67,7 @@ func (s *Subcommand) Main(ctx context.Context) { // if the database is not good, truncate it and restart if !isGood { - log.Infof("rm -rf %s", s.Database) + log.Infof("rm -f %s", s.Database) _ = os.Remove(s.Database) } diff --git a/internal/cmd/gardener/internal/sync/sync.go b/internal/cmd/gardener/internal/sync/sync.go index 1f18cd00e..c5f1360f1 100644 --- a/internal/cmd/gardener/internal/sync/sync.go +++ b/internal/cmd/gardener/internal/sync/sync.go @@ -44,7 +44,7 @@ func (s *Subcommand) Main() { // TODO(bassosimone): an alternative would be to somehow take note of the fact // that the database needs merging from an updated repository, but doing that // would require us to write a more complex diff. - runtimex.Try0(shellx.Run(log.Log, "rm", "-rf", s.DNSReportDatabase)) + runtimex.Try0(shellx.Run(log.Log, "rm", "-f", s.DNSReportDatabase)) // clone a new working copy runtimex.Try0(shellx.Run(log.Log, "git", "clone", testListsRepo, s.RepositoryDir)) diff --git a/internal/cmd/gardener/internal/sync/sync_test.go b/internal/cmd/gardener/internal/sync/sync_test.go index 605f2020c..dbbba8df4 100644 --- a/internal/cmd/gardener/internal/sync/sync_test.go +++ b/internal/cmd/gardener/internal/sync/sync_test.go @@ -85,7 +85,7 @@ func TestWorkingAsIntended(t *testing.T) { // expectations for commands expect := []string{ fmt.Sprintf("rm -rf %s", repodir), - fmt.Sprintf("rm -rf %s", dnsreportfile), + fmt.Sprintf("rm -f %s", dnsreportfile), fmt.Sprintf("git clone https://github.com/citizenlab/test-lists %s", repodir), fmt.Sprintf("cd %s", repodir), "git checkout -b gardener_20230315T114300Z",