Skip to content

Devel#16

Merged
bigin merged 2 commits into
masterfrom
devel
Sep 16, 2022
Merged

Devel#16
bigin merged 2 commits into
masterfrom
devel

Conversation

@bigin
Copy link
Copy Markdown
Owner

@bigin bigin commented Sep 16, 2022

No description provided.

@bigin bigin merged commit ec71cd3 into master Sep 16, 2022
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.
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