Skip to content

Commit

Permalink
prevent missuse of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Equanox committed Mar 31, 2023
1 parent efda6ff commit 667167c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bobtask/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (t *Task) Clean(invalidFiles map[string][]target.Reason, verbose ...bool) e
if t.target != nil {
boblog.Log.V(5).Info(fmt.Sprintf("Cleaning targets for task %s", t.Name()))

homeDir, err := os.UserHomeDir()
if err != nil {
return err
}

if vb {
fmt.Printf("Cleaning targets of task %s \n", t.name)
}
Expand All @@ -36,6 +41,10 @@ func (t *Task) Clean(invalidFiles map[string][]target.Reason, verbose ...bool) e
fmt.Printf(" %s ", filename)
}

if filename == "/" || filename == homeDir {
return fmt.Errorf("Cleanup of %s is not allowed", filename)
}

err := os.RemoveAll(filename)
if err != nil {
if vb {
Expand Down

0 comments on commit 667167c

Please sign in to comment.