Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
8847b866
Commit
8847b866
authored
Apr 09, 2016
by
stevemessick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validity checks to create (#3215)
* Add validity checks to create * Adjust indent
parent
d9e0c32d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletion
+54
-1
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+28
-1
create_test.dart
packages/flutter_tools/test/create_test.dart
+26
-0
No files found.
packages/flutter_tools/lib/src/commands/create.dart
View file @
8847b866
...
...
@@ -88,6 +88,10 @@ class CreateCommand extends Command {
String
dirPath
=
path
.
normalize
(
projectDir
.
absolute
.
path
);
String
projectName
=
_normalizeProjectName
(
path
.
basename
(
dirPath
));
if
(
_validateProjectDir
(
dirPath
)
!=
null
)
{
printError
(
_validateProjectDir
(
dirPath
));
return
1
;
}
if
(
_validateProjectName
(
projectName
)
!=
null
)
{
printError
(
_validateProjectName
(
projectName
));
return
1
;
...
...
@@ -217,9 +221,32 @@ final Set<String> _packageDependencies = new Set<String>.from(<String>[
String
_validateProjectName
(
String
projectName
)
{
if
(
_packageDependencies
.
contains
(
projectName
))
{
return
"Invalid project name: '
$projectName
' - this will conflict with Flutter "
"package dependencies."
;
"package dependencies."
;
}
return
null
;
}
/// 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
);
if
(
type
!=
FileSystemEntityType
.
NOT_FOUND
)
{
switch
(
type
)
{
case
FileSystemEntityType
.
DIRECTORY
:
// Do not re-use directory if it is not empty.
if
(
new
Directory
(
projectName
).
listSync
(
followLinks:
false
).
isNotEmpty
)
{
return
"Invalid project name: '
$projectName
' - refers to a directory "
"that is not empty."
;
};
break
;
case
FileSystemEntityType
.
FILE
:
// Do not overwrite files.
return
"Invalid project name: '
$projectName
' - file exists."
;
case
FileSystemEntityType
.
LINK
:
// Do not overwrite links.
return
"Invalid project name: '
$projectName
' - refers to a link."
;
}
}
return
null
;
}
...
...
packages/flutter_tools/test/create_test.dart
View file @
8847b866
...
...
@@ -48,5 +48,31 @@ void main() {
},
// This test can take a while due to network requests.
timeout:
new
Timeout
(
new
Duration
(
minutes:
2
)));
// Verify that we fail with an error code when the file exists.
testUsingContext
(
'fails when file exists'
,
()
async
{
ArtifactStore
.
flutterRoot
=
'../..'
;
CreateCommand
command
=
new
CreateCommand
();
CommandRunner
runner
=
new
CommandRunner
(
'test_flutter'
,
''
)
..
addCommand
(
command
);
File
existingFile
=
new
File
(
"
${temp.path.toString()}
/bad"
);
if
(!
existingFile
.
existsSync
())
existingFile
.
createSync
();
await
runner
.
run
([
'create'
,
existingFile
.
path
])
.
then
((
int
code
)
=>
expect
(
code
,
equals
(
1
)));
});
// Verify that we fail with an error code when the file exists.
testUsingContext
(
'fails with non-empty directory'
,
()
async
{
ArtifactStore
.
flutterRoot
=
'../..'
;
CreateCommand
command
=
new
CreateCommand
();
CommandRunner
runner
=
new
CommandRunner
(
'test_flutter'
,
''
)
..
addCommand
(
command
);
File
existingFile
=
new
File
(
"
${temp.path.toString()}
/bad"
);
if
(!
existingFile
.
existsSync
())
existingFile
.
createSync
();
RandomAccessFile
raf
=
existingFile
.
openSync
();
raf
.
close
();
await
runner
.
run
([
'create'
,
temp
.
path
])
.
then
((
int
code
)
=>
expect
(
code
,
equals
(
1
)));
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment