Skip to content

fix(clean): keep Coursier's JDK and sbt dependency cache out of cleanup - #2234

Merged
tw93 merged 2 commits into
tw93:mainfrom
viniciusdsandrade:fix/2233-keep-coursier-cache
Dec 4, 2026
Merged

tw93 merged 2 commits into
tw93:mainfrom
viniciusdsandrade:fix/2233-keep-coursier-cache

Conversation

@viniciusdsandrade

Copy link
Copy Markdown
Contributor

Summary

Closes #2233

The User app cache row in clean_user_essentials removes each folder under ~/Library/Caches as a whole (lib/clean/user.sh:343-388), and nothing kept ~/Library/Caches/Coursier. On macOS that folder holds Coursier's artifact cache (v1), where sbt 1.3 and later resolves dependencies by default, and its archive cache (arc), where cs setup installs a JDK when it finds none and points JAVA_HOME at it in the shell profile files. After mo clean, JAVA_HOME named a folder that no longer existed until cs setup ran again, and the next sbt build downloaded every dependency again. clean_dev_jvm leaves sbt's older stores (~/.ivy2/cache, ~/.sbt/boot, ~/.sbt/launchers) alone on purpose (lib/clean/dev.sh:3522-3530).

  • should_protect_path (lib/core/app_protection.sh) now keeps ~/Library/Caches/Coursier and everything below it, in the arm that keeps the Playwright, Camoufox, Cypress and Puppeteer folders, with a comment that says what the folder holds. The root pattern also covers jvm/, where Coursier before 2.1 kept its JVMs.
  • No setting or whitelist row, as for Puppeteer.

_safe_clean_impl checks should_protect_path for every target before sizing (bin/clean.sh:1037), in real and dry runs alike, so the sweep now logs the folder as SKIPPED ... protected and the preview no longer lists it. The other folders under ~/Library/Caches are swept as before.

Safety Review

  • Does this change affect cleanup, uninstall, optimize, installer, remove, analyze delete, update, or install behavior?
    • Yes: mo clean no longer removes ~/Library/Caches/Coursier. Nothing new is swept or deleted.
  • Does this change affect path validation, protected directories, symlink handling, sudo boundaries, or release/install integrity?
    • Yes: it adds */Library/Caches/Coursier | */Library/Caches/Coursier/* to should_protect_path.
  • If yes, describe the new boundary or risk change clearly.
    • Coursier's artifact and archive caches, with the JDKs it manages, are protected from cleanup. The change only narrows what cleanup can remove.

Tests

  • Automated checks (./scripts/check.sh, ./scripts/test.sh via GitHub Actions CI on this PR)
  • Manual verification

tests/core_safe_functions.bats: should_protect_path applies high-risk cleanup denylist now requires the folder itself, a JDK's bin/java under arc (the layout of the cs java-home examples in Coursier's doc/docs/cli-java.md, with the Contents/Home of a macOS JDK) and a Scala jar under v1.

tests/clean_user_core.bats: clean_user_essentials keeps Coursier's JDK and sbt dependency cache (#2233), next to the #1607 case it follows. It drives the real safe_clean_guarded path in a fixture HOME and requires the JDK and the jar to survive, while an ordinary-app cache root beside them is removed, so the sweep is known to have run.

On main, no branch of should_protect_path matches these paths: the protected bundle globs and the should_protect_data names hold nothing for Coursier, Java or Scala, and the sweep's own filters (the name case, the Chromium singleton check, the Deno root) do not apply. So both cases fail there.

Commits:

  • 112867a2 fix(clean): keep Coursier's JDK and sbt dependency cache out of cleanup
  • 789f4f28 test(clean): cover the Coursier folder in the user cache sweep

Safety-related changes

  • Protects ~/Library/Caches/Coursier and everything below it against removal by the user cache sweep and any other sink that checks should_protect_path.

The User app cache sweep removes each folder under ~/Library/Caches as
a whole, and nothing kept ~/Library/Caches/Coursier. On macOS that
folder holds Coursier's artifact cache (v1), where sbt 1.3 and later
resolves dependencies by default, and its archive cache (arc), where
cs setup installs a JDK when it finds none and points JAVA_HOME at it
in the shell profile files. After mo clean, JAVA_HOME named a folder
that no longer existed until cs setup ran again, and the next sbt build
downloaded every dependency again, while clean_dev_jvm leaves sbt's
older stores (~/.ivy2/cache, ~/.sbt/boot) alone on purpose.

should_protect_path now keeps the folder next to the other tools that
run from ~/Library/Caches (Playwright, Camoufox, Cypress, Puppeteer).
No setting or whitelist row.

Refs tw93#2233
The high-risk denylist case now requires should_protect_path to keep
~/Library/Caches/Coursier, a JDK under arc and a jar under v1. A new
clean_user_essentials case drives the real safe_clean_guarded path in
a fixture HOME and requires the JDK and the jar to survive, while an
ordinary cache root beside them is removed, so the sweep is known to
have run. Without the protection, should_protect_path returns 1 for
these paths and the sweep takes the folder, so both cases fail.

Refs tw93#2233
@tw93
tw93 merged commit 0a15b40 into tw93:main Dec 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] mo clean removes ~/Library/Caches/Coursier, which holds sbt's dependency store and the JDK that cs setup points JAVA_HOME at

2 participants