Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Unified Diff: lib/src/entrypoint.dart

Issue 1956543002: Fix a lockfile freshness checking bug. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/src/package.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/entrypoint.dart
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart
index dc1a4a445f6f95eacab95ac2e73ee75c5f2fddd2..e0c6774a9c227945f26faff7fd8d843a585b76a8 100644
--- a/lib/src/entrypoint.dart
+++ b/lib/src/entrypoint.dart
@@ -11,6 +11,7 @@ import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'barback/asset_environment.dart';
+import 'exceptions.dart';
import 'io.dart';
import 'lock_file.dart';
import 'log.dart' as log;
@@ -466,7 +467,8 @@ class Entrypoint {
var touchedLockFile = false;
if (lockFileModified.isBefore(pubspecModified) ||
hasPathDependencies) {
- if (_isLockFileUpToDate() && _arePackagesAvailable()) {
+ _assertLockFileUpToDate();
+ if (_arePackagesAvailable()) {
touchedLockFile = true;
touch(lockFilePath);
} else {
@@ -500,22 +502,36 @@ class Entrypoint {
/// Determines whether or not the lockfile is out of date with respect to the
/// pubspec.
///
- /// This will be `false` if any mutable pubspec contains dependencies that are
- /// not in the lockfile or that don't match what's in there.
- bool _isLockFileUpToDate() {
- if (!root.immediateDependencies.every(_isDependencyUpToDate)) return false;
+ /// If any mutable pubspec contains dependencies that are not in the lockfile
+ /// or that don't match what's in there, this will throw a [DataError]
+ /// describing the issue.
+ void _assertLockFileUpToDate() {
+ if (!root.immediateDependencies.every(_isDependencyUpToDate)) {
+ dataError('The pubspec.yaml file has changed since the pubspec.lock '
+ 'file was generated, please run "pub get" again.');
+ }
var overrides = root.dependencyOverrides.map((dep) => dep.name).toSet();
// Check that uncached dependencies' pubspecs are also still satisfied,
// since they're mutable and may have changed since the last get.
- return lockFile.packages.values.every((id) {
- var source = cache.sources[id.name];
- if (source is! CachedSource) return true;
+ for (var id in lockFile.packages.values) {
+ var source = cache.sources[id.source];
+ if (source is CachedSource) continue;
+
+ try {
+ if (cache.sources.load(id).dependencies.every((dep) =>
+ overrides.contains(dep.name) || _isDependencyUpToDate(dep))) {
+ continue;
+ }
+ } on FileException {
+ // If we can't load the pubpsec, the user needs to re-run "pub get".
+ }
- return cache.sources.load(id).dependencies.every((dep) =>
- overrides.contains(dep.name) || _isDependencyUpToDate(dep));
- });
+ dataError('${p.join(source.getDirectory(id), 'pubspec.yaml')} has '
+ 'changed since the pubspec.lock file was generated, please run "pub '
+ 'get" again.');
+ }
}
/// Returns whether the locked version of [dep] matches the dependency.
« no previous file with comments | « no previous file | lib/src/package.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698