Skip to content

Verify cached packages' pubspec.yaml exists in isResolutionUpToDate - #4939

Open
sigurdm wants to merge 4 commits into
dart-lang:mainfrom
sigurdm:issue-4559-check-cached-pubspec-exists
Open

sigurdm wants to merge 4 commits into
dart-lang:mainfrom
sigurdm:issue-4559-check-cached-pubspec-exists

Conversation

@sigurdm

@sigurdm sigurdm commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

In Entrypoint.isResolutionUpToDate, check that pubspec.yaml exists before skipping cached packages.

Previously, packages within cache.rootDir were skipped before verifying file existence with tryStatFile. On the fast path (all timestamps in order) nothing else looked at those packages, so if a cached package had been deleted from the pub cache, isResolutionUpToDate still considered the resolution up-to-date, and commands such as dart pub deps --json failed later in Package.load with Could not find a file named "pubspec.yaml". (The slow path already caught this in isPackageConfigUpToDate.) Cached packages still skip the timestamp comparison, since their mtimes say nothing about the current resolution.

The resulting implicit pub get only redownloads a hosted package when its directory is missing. To make the repair work when the directory is present but pubspec.yaml inside it is gone, HostedSource.downloadToSystemCache now treats such an entry as damaged and redownloads it (with a warning), mirroring the existing handling of a wrong content hash.

Cost: one extra stat per cached package on every up-to-date check. Measured on a 121-dependency project: +1.1 ms per invocation with a warm filesystem cache (≈10 µs/package); with a cold dentry cache on a network-backed disk (cloud VM, CI) ≈0.3 ms/package, i.e. tens of ms once for a few hundred packages, after which the cache is warm.

Fixes #4559.

Checking that pubspecPath exists before skipping cached packages ensures that missing cached dependencies trigger a re-resolution instead of crashing in Package.load.
Also replace the stale reference to the removed `_arePackagesAvailable` in
`isPackageConfigUpToDate` with a description of why that check is still
needed next to the one in the main loop.
`isResolutionUpToDate` now triggers a resolution when a cached package has no
`pubspec.yaml`, but `HostedSource.downloadToSystemCache` only redownloaded a
package when its directory was missing. With the directory present and the
`pubspec.yaml` gone the implicit `pub get` therefore left the entry alone and
`Package.load` failed with the same error as before, on every invocation.

Treat such an entry as damaged and redownload it, like a wrong content hash.
@sigurdm
sigurdm requested a review from jonasfj October 13, 2026 12:00
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.

Frequent instances of "Could not find a file named "pubspec.yaml"" when running dart pub deps --json

1 participant