Repository navigation
Never follow symlinks in workspace globs - #4949
Conversation
sigurdm
left a comment
There was a problem hiding this comment.
Thanks for tracking this down and putting together a clean PR!
I'm hesitant to add {glob: ..., follow_links: bool} to the pubspec.yaml schema for this. Nobody writing workspace: [packages/**] actually wants pub to follow Flutter's .plugin_symlinks into ~/.pub-cache (or follow symlink cycles in example/ apps), so requiring users to hit the failure and opt into follow_links: false feels like exposing a workaround in configuration rather than fixing the default behavior.
Instead of introducing new pubspec.yaml syntax and a language version gate, what if workspace glob expansion in Package.load simply never follows symlinks (followLinks: false and if (globResult is! Directory) continue;)?
- Literal workspace entries (
workspace: [pkgs/external]) don't go throughGlob(since #4852), so explicitly listed symlinked packages would still work. - Passing
followLinks: falseand checkingglobResult is Directorywhen expanding globs avoids following.plugin_symlinks/.symlinks(and avoidsstatingpubspec.yamlon regular files matched by**) with no config needed.
(As a side note, packages/* and packages/*/* is generally preferable to packages/** in large repos anyway, because ** forces package:glob to Directory.listSync(recursive: true) through every lib/, build/, .dart_tool/, and test/ folder under packages/.)
|
@sigurdm that sounds like a better solution indeed, I'll update the PR! |
Follow-up to #4949. `package:glob` steps straight into literal segments on case-sensitive platforms, so `followLinks: false` doesn't apply to them. With `linked/*`, where `linked` is a symlink, packages behind the link become workspace members. On Windows, globs are case-insensitive and every segment is listed, so the same pubspec doesn't pick them up. Skip any glob match that is a symlink or is reached through one below the workspace root, so all platforms behave the same.
Problem
Workspace globs follow symlinks. In a Flutter app with desktop platform folders,
flutter pub getcreates plugin symlinks such aslinux/flutter/ephemeral/.plugin_symlinks/<plugin>. A glob likepackages/**matches those, and because the plugins have noresolution: workspace, the nextpub getfails:The only workaround is to replace
**with a list of fixed depths, such aspackages/*andpackages/*/*, as Flame had to do.Solution
Workspace globs no longer follow or match symlinks.
followLinks: falsealone isn't enough, becausepackage:globstill returns the symlink itself and itspubspec.yamlis still found through the link, so anything that isn't a directory is skipped too.Symlinked packages can still be members by listing them as literal entries, since those don't go through
Glob. A package that was only picked up through a symlink in a glob needs that literal entry after this change.Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.