Skip to content

Commit afbfe5c

Browse files
committed
refactor: optimize dev clean checks and update security audit
1 parent f177686 commit afbfe5c

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

SECURITY_AUDIT.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ The analyzer (`mo analyze`) uses a distinct security model:
145145

146146
**Code:** `lib/clean/apps.sh:orphan_detection()`
147147

148+
#### New Language Ecosystem Support (v1.19.1+)
149+
150+
Added support for Elixir, Haskell, OCaml, and Editors (VS Code, Zed) with strict safety checks:
151+
152+
- **Existence Checks:** Cleanup logic only runs if the tool is installed (directory exists).
153+
- **Safe Targets:** Only volatile caches are cleaned (e.g., `~/.hex/cache`).
154+
- **Protected Paths:** Critical directories like `~/.mix/archives` (installed tools) and `~/.stack/programs` (installed compilers) are explicitly **excluded**.
155+
148156
#### Active Uninstallation Heuristics
149157

150158
For user-selected app removal:

lib/clean/dev.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,24 +257,34 @@ clean_sqlite_temp_files() {
257257
}
258258
# Elixir/Erlang ecosystem.
259259
clean_dev_elixir() {
260-
# safe_clean ~/.mix/archives/* "Mix cache"
261-
safe_clean ~/.hex/cache/* "Hex cache"
260+
if [[ -d ~/.mix ]] || [[ -d ~/.hex ]]; then
261+
# safe_clean ~/.mix/archives/* "Mix cache"
262+
safe_clean ~/.hex/cache/* "Hex cache"
263+
fi
262264
}
263265
# Haskell ecosystem.
264266
clean_dev_haskell() {
265-
safe_clean ~/.cabal/packages/* "Cabal install cache"
266-
# safe_clean ~/.stack/programs/* "Stack cache"
267+
if [[ -d ~/.cabal ]] || [[ -d ~/.stack ]]; then
268+
safe_clean ~/.cabal/packages/* "Cabal install cache"
269+
# safe_clean ~/.stack/programs/* "Stack cache"
270+
fi
267271
}
268272
# OCaml ecosystem.
269273
clean_dev_ocaml() {
270-
safe_clean ~/.opam/download-cache/* "Opam cache"
274+
if [[ -d ~/.opam ]]; then
275+
safe_clean ~/.opam/download-cache/* "Opam cache"
276+
fi
271277
}
272278
# Editor caches.
273279
clean_dev_editors() {
274-
safe_clean ~/Library/Caches/com.microsoft.VSCode/Cache/* "VS Code cached data"
275-
safe_clean ~/Library/Application\ Support/Code/CachedData/* "VS Code cached data"
276-
# safe_clean ~/Library/Application\ Support/Code/User/workspaceStorage/* "VS Code workspace storage"
277-
safe_clean ~/Library/Caches/Zed/* "Zed cache"
280+
if [[ -d ~/Library/Caches/com.microsoft.VSCode ]] || [[ -d ~/Library/Application\ Support/Code ]]; then
281+
safe_clean ~/Library/Caches/com.microsoft.VSCode/Cache/* "VS Code cached data"
282+
safe_clean ~/Library/Application\ Support/Code/CachedData/* "VS Code cached data"
283+
# safe_clean ~/Library/Application\ Support/Code/User/workspaceStorage/* "VS Code workspace storage"
284+
fi
285+
if [[ -d ~/Library/Caches/Zed ]]; then
286+
safe_clean ~/Library/Caches/Zed/* "Zed cache"
287+
fi
278288
}
279289
# Main developer tools cleanup sequence.
280290
clean_developer_tools() {

tests/dev_extended.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ teardown_file() {
2121
}
2222

2323
@test "clean_dev_elixir cleans mix and hex caches" {
24+
mkdir -p "$HOME/.mix" "$HOME/.hex"
2425
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
2526
set -euo pipefail
2627
source "$PROJECT_ROOT/lib/core/common.sh"
@@ -35,6 +36,7 @@ EOF
3536
}
3637

3738
@test "clean_dev_haskell cleans cabal install and stack caches" {
39+
mkdir -p "$HOME/.cabal" "$HOME/.stack"
3840
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
3941
set -euo pipefail
4042
source "$PROJECT_ROOT/lib/core/common.sh"
@@ -49,6 +51,7 @@ EOF
4951
}
5052

5153
@test "clean_dev_ocaml cleans opam cache" {
54+
mkdir -p "$HOME/.opam"
5255
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
5356
set -euo pipefail
5457
source "$PROJECT_ROOT/lib/core/common.sh"
@@ -62,6 +65,7 @@ EOF
6265
}
6366

6467
@test "clean_dev_editors cleans VS Code and Zed caches" {
68+
mkdir -p "$HOME/Library/Caches/com.microsoft.VSCode" "$HOME/Library/Application Support/Code" "$HOME/Library/Caches/Zed"
6569
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
6670
set -euo pipefail
6771
source "$PROJECT_ROOT/lib/core/common.sh"

0 commit comments

Comments
 (0)