diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index e8d5525afc2..35576d578de 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -91,13 +91,15 @@ class CreateCommand extends FlutterCommand { String relativePath = path.relative(dirPath); String projectName = _normalizeProjectName(path.basename(dirPath)); - if (_validateProjectDir(dirPath) != null) { - printError(_validateProjectDir(dirPath)); + String error =_validateProjectDir(dirPath, flutterRoot: flutterRoot); + if (error != null) { + printError(error); return 1; } - if (_validateProjectName(projectName) != null) { - printError(_validateProjectName(projectName)); + error = _validateProjectName(projectName); + if (error != null) { + printError(error); return 1; } @@ -242,17 +244,22 @@ String _validateProjectName(String projectName) { /// Return `null` if the project directory is legal. Return a validation message /// if we should disallow the directory name. -String _validateProjectDir(String projectName) { - FileSystemEntityType type = FileSystemEntity.typeSync(projectName); +String _validateProjectDir(String dirPath, { String flutterRoot }) { + if (path.isWithin(flutterRoot, dirPath)) { + return "Cannot create a project within the Flutter SDK.\n" + "Target directory '$dirPath' is within the Flutter SDK at '$flutterRoot'."; + } + + FileSystemEntityType type = FileSystemEntity.typeSync(dirPath); if (type != FileSystemEntityType.NOT_FOUND) { switch(type) { case FileSystemEntityType.FILE: // Do not overwrite files. - return "Invalid project name: '$projectName' - file exists."; + return "Invalid project name: '$dirPath' - file exists."; case FileSystemEntityType.LINK: // Do not overwrite links. - return "Invalid project name: '$projectName' - refers to a link."; + return "Invalid project name: '$dirPath' - refers to a link."; } }