---
title: "dangerous-directory-removal"
description: "Detect removal of whole system or user directories."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# dangerous-directory-removal

**Default severity:** `error`

Passing the direct result of `os.TempDir` or a user directory helper to
`os.RemoveAll` deletes the entire shared directory rather than an
application-owned child. This is commonly caused by confusing `TempDir` with a
directory-creation helper or forgetting to append a suffix.

The check covers the temporary, user cache, user configuration, and user
home directory helpers.

## Bad

```go
directory := os.TempDir(); defer os.RemoveAll(directory)
```

## Good

```go
directory, err := os.MkdirTemp(os.TempDir(), `app-*`); defer os.RemoveAll(directory)
```

Source: https://strider.gempir.com/analyzers/dangerous-directory-removal/index.mdx
