[flutter_tools] prevent NPE due to moved/deleted packages during upgrade packages (#73357)

This commit is contained in:
Jonah Williams 2021-01-05 18:49:02 -08:00 committed by GitHub
parent 7c618758bb
commit c2ce0e68c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1425,12 +1425,13 @@ Directory createTemporaryFlutterSdk(
Directory realFlutter,
List<PubspecYaml> pubspecs,
) {
final Set<String> currentPackages = realFlutter
.childDirectory('packages')
.listSync()
.whereType<Directory>()
.map((Directory directory) => fileSystem.path.basename(directory.path))
.toSet();
final Set<String> currentPackages = <String>{};
for (final FileSystemEntity entity in realFlutter.childDirectory('packages').listSync()) {
// Verify that a pubspec.yaml exists to ensure this isn't a left over directory.
if (entity is Directory && entity.childFile('pubspec.yaml').existsSync()) {
currentPackages.add(fileSystem.path.basename(entity.path));
}
}
final Map<String, PubspecYaml> pubspecsByName = <String, PubspecYaml>{};
for (final PubspecYaml pubspec in pubspecs) {