Commit 646b5350 authored by Devon Carew's avatar Devon Carew

resolve symlinks in paths to flutter (#4219)

* resolve symlinks in paths to flutter

* review comments
parent d6aed1e7
...@@ -273,12 +273,13 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -273,12 +273,13 @@ class FlutterCommandRunner extends CommandRunner {
// Check if the cwd is a flutter dir. // Check if the cwd is a flutter dir.
while (directory.isNotEmpty) { while (directory.isNotEmpty) {
if (_isDirectoryFlutterRepo(directory)) { if (_isDirectoryFlutterRepo(directory)) {
if (directory != Cache.flutterRoot) { if (!_compareResolvedPaths(directory, Cache.flutterRoot)) {
// Warn, but continue execution.
printError( printError(
'Warning - the active Flutter is not the one from the current directory:\n' 'Warning: the \'flutter\' tool you are currently running is not the one from the current directory:\n'
' active Flutter : ${Cache.flutterRoot}\n' ' running Flutter : ${Cache.flutterRoot}\n'
' current directory: $directory\n' ' current directory: $directory\n'
'This can happen when you have multiple copies of flutter installed. Please check your system path to verify\n'
'that you\'re running the expected version (run \'flutter --version\' to see which flutter is on your path).\n'
); );
} }
...@@ -301,14 +302,15 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -301,14 +302,15 @@ class FlutterCommandRunner extends CommandRunner {
Uri rootUri = flutterUri.resolve('../../..'); Uri rootUri = flutterUri.resolve('../../..');
String flutterPath = path.normalize(new File.fromUri(rootUri).absolute.path); String flutterPath = path.normalize(new File.fromUri(rootUri).absolute.path);
if (flutterPath != Cache.flutterRoot) { if (!_compareResolvedPaths(flutterPath, Cache.flutterRoot)) {
// Warn and exit the app.
printError( printError(
'Warning - the active Flutter is different from the one referenced in your pubspec:\n' 'Warning: the \'flutter\' tool you are currently running is different from the one referenced in your pubspec.yaml:\n'
' active Flutter : ${Cache.flutterRoot}\n' ' running Flutter : ${Cache.flutterRoot}\n'
' pubspec reference: $flutterPath' ' pubspec reference: $flutterPath\n'
'This can happen when you have multiple copies of flutter installed. Please check your system path to verify\n'
'that you\'re running the expected version (run \'flutter --version\' to see which flutter is on your path). You\n'
'can also change which flutter your project points to by editing the \'flutter:\' path in your pubspec.yaml file.\n'
); );
return false;
} }
} }
} }
...@@ -323,3 +325,10 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -323,3 +325,10 @@ class FlutterCommandRunner extends CommandRunner {
FileSystemEntity.isFileSync(path.join(directory, 'bin/cache/engine.stamp')); FileSystemEntity.isFileSync(path.join(directory, 'bin/cache/engine.stamp'));
} }
} }
bool _compareResolvedPaths(String path1, String path2) {
path1 = new Directory(path.absolute(path1)).resolveSymbolicLinksSync();
path2 = new Directory(path.absolute(path2)).resolveSymbolicLinksSync();
return path1 == path2;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment