Commit 030f623a authored by Adam Barth's avatar Adam Barth Committed by GitHub

Prevent `flutter create` from running inside SDK (#6587)

Fixes #6480
parent 02883908
......@@ -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.";
}
}
......
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