Skip to content

refactor: Extract interruptible directory-removal abstraction - #1700

Open
d3xter666 wants to merge 2 commits into
mainfrom
refactor/cache-interruptible-removal
Open

d3xter666 wants to merge 2 commits into
mainfrom
refactor/cache-interruptible-removal

Conversation

@d3xter666

@d3xter666 d3xter666 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

JIRA: CPOUI5FOUNDATION-1394

The framework cache clean uses an atomic rename-then-delete pattern: synchronously rename the directory so it disappears immediately, then asynchronously remove it — with the ability to resume if the process is killed in between. This logic is currently inlined in FrameworkCache.

This PR extracts it into a reusable lib/utils/interruptibleRemoval.js helper (markForRemoval, removePendingDir, scanPendingRemovals). No behavior changes — FrameworkCache is simply wired to use the helper instead of its own inline copy.

The motivation is: extending ui5 cache clean to remove all outdated build-cache version directories.
Each build-cache version directory contains a single SQLite database (cache.db). The current version's database is cleaned by dropping all tables and running a deferred VACUUM — an operation that is both fast and schema-aware. Older version directories might not be able to be opened with the current BuildCacheStorage: the schema may change across versions, and attempting to DROP TABLE against an incompatible schema may produce a misleading "already performed by another process" error. Because the data in those directories is by definition stale and no longer readable by the current CLI, there is no reason to open them at all. Treating them as opaque filesystem directories and removing them with rename + rm is both simpler and safer.

…then-delete

markForRemoval uses fs.renameSync so the directory vanishes in the same
execution frame — no event-loop yield between call and rename completing.
removePendingDir and scanPendingRemovals are async (background cleanup).
FrameworkCache now delegates its inline rename-then-delete and stale-dir
scan logic to these helpers. Zero behavior change.
Prepares the abstraction for reuse in build-cache older-version cleanup.

This branch has not been deployed

No deployments
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.

1 participant