Skip to content

Commit

Permalink
fix: avoid using rm -rf for a regular file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bassosimone committed Feb 14, 2024
1 parent 31da778 commit eef679b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/gardener/internal/dnsreport/dnsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/gardener/internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/gardener/internal/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit eef679b

Please sign in to comment.