Conversation
bigin
added a commit
that referenced
this pull request
May 4, 2026
…cleanup Two bugs in the on-disk cleanup path showed up after a page-delete: 1) Empty `<itemId>/<fieldId>/...` directories were left behind. The asset bytes and thumbnails were removed cleanly, but the directory chain itself (including the now-empty `thumbnail/` subdir) stayed on disk indefinitely, so deleting many pages slowly accumulated stale folders. 2) Thumbnail purge matched against `File.name` instead of the path basename. After a collision-free upload (e.g. a second `foo.png` lands at `<dir>/foo-2.png` while keeping `name = "foo.png"`), thumbnails are written as `300x300_foo-2.png` (path stem). The old purge looked for `*_foo.png` and would have wiped the *first* upload's thumbnail while leaving the actual `_foo-2.png` thumbnail orphaned. Item #17 in the live db reproduced both: directories left over, and `300x300_auz-3.png` orphaned in `13/7/thumbnail/`. Both call sites — the page-delete listener and the per-file DELETE endpoint — now funnel through a single `Scriptor\Boot\Files\DirectoryCleanup` helper that: - deletes the asset bytes, - walks `<dir>/thumbnail/` and removes every `<W>x<H>_<basename>` entry where the basename is taken from the path (matches what's actually written to disk), - rmdir's the thumbnail directory once it goes empty, - walks up the parent chain rmdir'ing each empty dir, stopping before the storage root so siblings with their own files are untouched. The endpoint's existing `if ($storage->exists($thumbDir))` guard was also wrong on its own — `exists()` checks `is_file()`, so the guard was always false for a directory and the thumbnail loop never ran. Replacing the inline logic with the helper drops that dead branch and gives DELETE the same scandir-based purge the listener already used for ItemDeleted. Smoke (against the live storage): - Synthetic page + 3-way collision upload (foo.png, foo-2.png, foo-3.png with 300x300 thumbnails for each) → page delete → itemDir, all assets, all thumbnails, all parents removed. - Stale empty dirs from item #17 / test-15 / item #16 swept by hand in the same session.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.