Skip to content

fix(symlink-cleaner): detect symlinks via resolved path instead of stat mode - #288

Merged
dermatz merged 5 commits into
mainfrom
fix/symlink-cleaner-detection
Nov 12, 2026
Merged

dermatz merged 5 commits into
mainfrom
fix/symlink-cleaner-detection

Conversation

@dermatz

@dermatz dermatz commented Nov 12, 2026

Copy link
Copy Markdown
Member

Problem

SymlinkCleaner::isSymlink() checked the S_IFLNK bit of FileDriver::stat(). stat() follows symlinks and returns the mode of the link target, so symlinks in {theme}/web/css/ were never detected and never removed in developer mode. The existing unit tests mocked stat() with a symlink mode, which hid the bug.

Fix

  • Detect symlinks via FileDriver::getRealPath(): an entry whose real path differs from <real css dir>/<name> is a symlink. This also works when the theme itself lives behind a symlinked directory.
  • Broken symlinks (real path cannot be resolved) are removed as well.
  • Tests now mock getRealPath() and add a test against the real filesystem (fails on the old implementation).

Verification

  • phpunit tests/Unit/Service/SymlinkCleanerTest.php: 10 tests pass
  • phpcs and phpstan clean for the changed files

The changelog entry is generated by Release Please from the title.

…at mode

SymlinkCleaner checked the S_IFLNK bit of FileDriver::stat(), but stat()
follows links and reports the target's mode, so symlinks in web/css were
never detected or removed. Compare the entry's real path with its expected
location in the resolved css directory instead; unresolvable (broken)
links are removed as well.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:09
@github-actions github-actions Bot added the Fix label Nov 12, 2026
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; no new actionable issues were found.

Summary

Changes SymlinkCleaner to detect links by comparing resolved paths instead of file modes.

  • Theme builds remove CSS symlinks by checking where each entry resolves.

Reviews (5) · Last reviewed commit: "fix(symlink-cleaner): treat backslash as..." · Reviewed by Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the CSS symlink cleanup change.

No open issues 🎉

What changed in this PR

Fixes developer-mode CSS symlink cleanup by replacing stat() mode checks with resolved-path comparisons.

Changes:

  • Detects symlinks while preserving regular files inside symlinked theme directories.
  • Removes broken symlinks whose paths cannot be resolved.
  • Updates mocked tests and adds a real-filesystem regression test.
File Description
tests/​Unit/​Service/​SymlinkCleanerTest.php Tests resolved-path detection, broken links, symlinked themes, and real-filesystem cleanup.
src/​Service/​SymlinkCleaner.php Compares resolved entry paths against the resolved CSS directory to identify symlinks.

Review effort: Balanced

Fixes the Generic.Files.LineLength.TooLong warning that fails the PHPCS check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The path comparison normalizes valid backslashes in POSIX filenames, causing cleanSymlinks() to delete regular files incorrectly.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve literal POSIX filenames when cleaning symlinks

src/​Service/​SymlinkCleaner.php:112

On POSIX filesystems, a backslash is a valid filename character, but getBasename() converts it into a directory separator. A regular file named custom\styles.css therefore resolves to <css>/custom\styles.css while this comparison expects <css>/styles.css, so cleanSymlinks() deletes the regular file. Preserve the entry's literal filename when constructing its expected path rather than using the separator-normalising display helper.

Review effort: Balanced

The Static Analysis workflow analyses the tests inside the Magento install,
which pins PHPUnit 10.5 where getStubBuilder() does not exist. The tests run
with the PHPUnit 12 required by composer.json, so ignore only this message.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A critical Windows path-separator mismatch causes regular CSS files to be misidentified as symlinks and deleted during cleanup.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Normalize Windows path separators before symlink comparison

src/​Service/​SymlinkCleaner.php:112

On Windows, a regular file resolves to C:\theme\web\css\styles.css, but this expression builds C:\theme\web\css/styles.css. The separator mismatch makes isSymlink() return true for regular files, so cleanup deletes the theme's actual CSS files. Normalise separators in both resolved paths before comparing them, and cover a backslash-separated regular-file path in the tests.

Review effort: Balanced

Take main's fix (#290) for getStubBuilder and the overlong line, and drop the
now redundant phpstan.neon ignore.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The symlink comparison can misclassify and delete regular POSIX files whose names contain backslashes, so entry names must be extracted using platform-aware separators.

1 open issue

Review effort: Balanced

Comment thread src/Service/SymlinkCleaner.php Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the developer-mode CSS symlink cleanup change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@dermatz
dermatz merged commit bba249c into main Nov 12, 2026
23 checks passed
@dermatz
dermatz deleted the fix/symlink-cleaner-detection branch November 12, 2026 22:49
@github-actions github-actions Bot mentioned this pull request Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants