From 294376fb01888e6bce5d368df9f0746e983375df Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 14 Jun 2016 12:39:20 -0700 Subject: [PATCH] fix reentrant locking in pub upgrade (#4556) --- packages/flutter_tools/lib/src/cache.dart | 5 ++--- packages/flutter_tools/lib/src/commands/upgrade.dart | 5 ++++- .../lib/src/runner/flutter_command_runner.dart | 8 +++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 079e6b64e5..08928b814f 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -55,7 +55,7 @@ class Cache { locked = true; } on FileSystemException { if (!printed) { - printStatus('Waiting to be able to obtain lock of Flutter cache directory...'); + printStatus('Waiting to be able to obtain lock of Flutter binary artifacts directory...'); printed = true; } await new Future/**/.delayed(const Duration(milliseconds: 50)); @@ -65,9 +65,8 @@ class Cache { /// Releases the lock. This is not necessary unless the process is long-lived. static void releaseLockEarly() { - if (!_lockEnabled) + if (!_lockEnabled || _lock == null) return; - assert(_lock != null); _lock.closeSync(); _lock = null; } diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index a06a8ac2ac..1d40a29fc3 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -45,10 +45,13 @@ class UpgradeCommand extends FlutterCommand { return code; // Check for and download any engine and pkg/ updates. + // We run the 'flutter' shell script re-entrantly here + // so that it will download the updated Dart and so forth + // if necessary. printStatus(''); printStatus('Upgrading engine...'); code = await runCommandAndStreamOutput([ - 'bin/flutter', '--no-color', 'precache' + 'bin/flutter', '--no-lock', '--no-color', 'precache' ], workingDirectory: Cache.flutterRoot); printStatus(''); diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index f25fbe063d..81e0472560 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -48,6 +48,11 @@ class FlutterCommandRunner extends CommandRunner { negatable: true, hide: !verboseHelp, help: 'Whether to use terminal colors.'); + argParser.addFlag('lock', + negatable: true, + hide: !verboseHelp, + help: 'Whether to lock the Flutter binary artifacts directory while running. (This prevents multiple simultaneous Flutter instances from colliding.)', + defaultsTo: true); argParser.addFlag('suppress-analytics', negatable: false, hide: !verboseHelp, @@ -142,7 +147,8 @@ class FlutterCommandRunner extends CommandRunner { // enginePath's initialiser uses it). Cache.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root'])); - await Cache.lock(); + if (globalResults['lock']); + await Cache.lock(); if (globalResults['suppress-analytics']) flutterUsage.suppressAnalytics = true;