Repository navigation
Fix renaming folders with differently cased subfolder paths - #20804
brandonkelly wants to merge 5 commits into
Conversation
Rebuild descendant folder paths from the parent/child hierarchy when a folder is renamed, and make ensureFolderByFullPathAndVolume() continue from an existing folder's actual path, since its lookup can be case-insensitive. Fixes #20773 Amp-Thread-ID: https://ampcode.com/threads/T-d76fdf59-13ae-40ce-bedf-b3d57d14879d Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
🟡 Changes recommended
Renaming and indexing can record asset paths without moving the corresponding files on case-sensitive storage, breaking access to existing assets.
2 open issues
What changed in this PR
This PR addresses #20773 by updating Craft’s asset-folder handling to keep descendant paths consistent when folder casing differs.
Changes:
- Rebuilds descendant paths through parent-child relationships during renames.
- Uses existing folders’ stored casing when resolving subfolder paths.
- Adds regression tests and changelog entries for both behaviors.
| File | Description |
|---|---|
| tests/unit/services/AssetsTest.php | Adds regression tests for mixed-case renames and subfolder creation. |
| src/services/Assets.php | Updates descendant traversal and path-case handling. |
| CHANGELOG.md | Documents both asset-folder fixes. |
Review effort: Balanced
Keep the original path for a subfolder whose path differs in case from its renamed parent's, unless its directory moved along with the parent, as on case-insensitive storage. Revert the ensureFolderByFullPathAndVolume() change, since the asset indexer uses it to record existing paths. Amp-Thread-ID: https://ampcode.com/threads/T-d76fdf59-13ae-40ce-bedf-b3d57d14879d Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
🟡 Changes recommended
Folder renames can leave descendant paths stale because of casing mismatches and skipped traversal, while the regression test can fail on case-insensitive filesystems.
2 open issues
2 resolved since last review
Review effort: Balanced
Keep the rest of each subfolder's stored path, rather than rebuilding it from its parent's, and check every subfolder, including those below one that kept its path. Amp-Thread-ID: https://ampcode.com/threads/T-d76fdf59-13ae-40ce-bedf-b3d57d14879d Co-authored-by: Amp <amp@ampcode.com>
Case variants such as Ⱥ and ⱥ differ in UTF-8 byte length, so slicing the prefix by bytes could skip subfolders that moved. Amp-Thread-ID: https://ampcode.com/threads/T-d76fdf59-13ae-40ce-bedf-b3d57d14879d Co-authored-by: Amp <amp@ampcode.com>
Case variants can differ in character count too, such as ß and SS, so take the prefix by path segment and compare it with full case folding. Amp-Thread-ID: https://ampcode.com/threads/T-d76fdf59-13ae-40ce-bedf-b3d57d14879d Co-authored-by: Amp <amp@ampcode.com>
|
Following up on the "Needs a closer look" note: case variants can also differ in character count ( |


Summary
Assets::renameFolderById()found descendants with a case-insensitiveLIKEon MySQL, then rewrote their paths with a case-sensitive regex. Subfolders stored asuploads/my-entry/under a folder atUploads/kept their old path after a rename, even when the filesystem had moved their directory with the parent.The rename now finds every subfolder by
parentIdand swaps the renamed folder's old path for its new one, keeping the rest of each stored path:Finding subfolders by
parentIdalso stops the rename from treating regex characters in the old path as a pattern, and from touching folders that only matched theLIKEprefix.Evidence
tests/unit/services/AssetsTest.phpbuilds the tree above on a Local filesystem, renamesUploadstoRenamed, and checks each subfolder's path. Theseparateexpectation depends on whether the filesystem moved it. It fails on5.x(uploads/moved/and its child keep their old paths) and passes with this change on MySQL and PostgreSQL.Related issues