Unverified Commit 34ba6473 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Clean up null assumptions in devfs to prep for null safety migration (#88934)

parent 4dba7d83
...@@ -37,8 +37,8 @@ const String kFontManifestJson = 'FontManifest.json'; ...@@ -37,8 +37,8 @@ const String kFontManifestJson = 'FontManifest.json';
const List<Map<String, Object>> kMaterialFonts = <Map<String, Object>>[ const List<Map<String, Object>> kMaterialFonts = <Map<String, Object>>[
<String, Object>{ <String, Object>{
'family': 'MaterialIcons', 'family': 'MaterialIcons',
'fonts': <Map<String, Object>>[ 'fonts': <Map<String, String>>[
<String, Object>{ <String, String>{
'asset': 'fonts/MaterialIcons-Regular.otf', 'asset': 'fonts/MaterialIcons-Regular.otf',
}, },
], ],
...@@ -161,7 +161,8 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -161,7 +161,8 @@ class ManifestAssetBundle implements AssetBundle {
@override @override
bool needsBuild({ String manifestPath = defaultManifestPath }) { bool needsBuild({ String manifestPath = defaultManifestPath }) {
if (_lastBuildTimestamp == null) { final DateTime lastBuildTimestamp = _lastBuildTimestamp;
if (lastBuildTimestamp == null) {
return true; return true;
} }
...@@ -179,13 +180,13 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -179,13 +180,13 @@ class ManifestAssetBundle implements AssetBundle {
if (dateTime == null) { if (dateTime == null) {
continue; continue;
} }
if (dateTime.isAfter(_lastBuildTimestamp)) { if (dateTime.isAfter(lastBuildTimestamp)) {
return true; return true;
} }
} }
} }
return stat.modified.isAfter(_lastBuildTimestamp); return stat.modified.isAfter(lastBuildTimestamp);
} }
@override @override
...@@ -267,9 +268,7 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -267,9 +268,7 @@ class ManifestAssetBundle implements AssetBundle {
if (!_splitDeferredAssets || !deferredComponentsEnabled) { if (!_splitDeferredAssets || !deferredComponentsEnabled) {
// Include the assets in the regular set of assets if not using deferred // Include the assets in the regular set of assets if not using deferred
// components. // components.
for (final String componentName in deferredComponentsAssetVariants.keys) { deferredComponentsAssetVariants.values.forEach(assetVariants.addAll);
assetVariants.addAll(deferredComponentsAssetVariants[componentName]);
}
deferredComponentsAssetVariants.clear(); deferredComponentsAssetVariants.clear();
deferredComponentsEntries.clear(); deferredComponentsEntries.clear();
} }
...@@ -457,7 +456,7 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -457,7 +456,7 @@ class ManifestAssetBundle implements AssetBundle {
return; return;
} }
final DevFSStringContent oldContent = entries[key] as DevFSStringContent; final DevFSStringContent oldContent = entries[key] as DevFSStringContent;
if (oldContent.string != content.string) { if (oldContent?.string != content.string) {
entries[key] = content; entries[key] = content;
} }
} }
...@@ -479,8 +478,8 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -479,8 +478,8 @@ class ManifestAssetBundle implements AssetBundle {
// the uncompressed strings to not incur decompression/decoding while making // the uncompressed strings to not incur decompression/decoding while making
// the comparison. // the comparison.
if (!entries.containsKey(_kNoticeZippedFile) || if (!entries.containsKey(_kNoticeZippedFile) ||
!(entries[_kNoticeZippedFile] as DevFSStringCompressingBytesContent) (entries[_kNoticeZippedFile] as DevFSStringCompressingBytesContent)
.equals(combinedLicenses)) { ?.equals(combinedLicenses) != true) {
entries[_kNoticeZippedFile] = DevFSStringCompressingBytesContent( entries[_kNoticeZippedFile] = DevFSStringCompressingBytesContent(
combinedLicenses, combinedLicenses,
// A zlib dictionary is a hinting string sequence with the most // A zlib dictionary is a hinting string sequence with the most
...@@ -494,8 +493,16 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -494,8 +493,16 @@ class ManifestAssetBundle implements AssetBundle {
List<_Asset> _getMaterialAssets() { List<_Asset> _getMaterialAssets() {
final List<_Asset> result = <_Asset>[]; final List<_Asset> result = <_Asset>[];
for (final Map<String, Object> family in kMaterialFonts) { for (final Map<String, Object> family in kMaterialFonts) {
for (final Map<String, Object> font in family['fonts'] as List<Map<String, Object>>) { final Object fonts = family['fonts'];
final Uri entryUri = _fileSystem.path.toUri(font['asset'] as String); if (fonts == null) {
continue;
}
for (final Map<String, Object> font in fonts as List<Map<String, String>>) {
final String asset = font['asset'] as String;
if (asset == null) {
continue;
}
final Uri entryUri = _fileSystem.path.toUri(asset);
result.add(_Asset( result.add(_Asset(
baseDir: _fileSystem.path.join(Cache.flutterRoot, 'bin', 'cache', 'artifacts', 'material_fonts'), baseDir: _fileSystem.path.join(Cache.flutterRoot, 'bin', 'cache', 'artifacts', 'material_fonts'),
relativeUri: Uri(path: entryUri.pathSegments.last), relativeUri: Uri(path: entryUri.pathSegments.last),
...@@ -577,22 +584,21 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -577,22 +584,21 @@ class ManifestAssetBundle implements AssetBundle {
Map<String, Map<_Asset, List<_Asset>>> deferredComponentsAssetVariants Map<String, Map<_Asset, List<_Asset>>> deferredComponentsAssetVariants
) { ) {
final Map<String, List<String>> jsonObject = <String, List<String>>{}; final Map<String, List<String>> jsonObject = <String, List<String>>{};
final List<_Asset> assets = assetVariants.keys.toList();
final Map<_Asset, List<String>> jsonEntries = <_Asset, List<String>>{}; final Map<_Asset, List<String>> jsonEntries = <_Asset, List<String>>{};
for (final _Asset main in assets) { assetVariants.forEach((_Asset main, List<_Asset> variants) {
jsonEntries[main] = <String>[ jsonEntries[main] = <String>[
for (final _Asset variant in assetVariants[main]) for (final _Asset variant in variants)
variant.entryUri.path, variant.entryUri.path,
]; ];
} });
if (deferredComponentsAssetVariants != null) { if (deferredComponentsAssetVariants != null) {
for (final Map<_Asset, List<_Asset>> componentAssets in deferredComponentsAssetVariants.values) { for (final Map<_Asset, List<_Asset>> componentAssets in deferredComponentsAssetVariants.values) {
for (final _Asset main in componentAssets.keys) { componentAssets.forEach((_Asset main, List<_Asset> variants) {
jsonEntries[main] = <String>[ jsonEntries[main] = <String>[
for (final _Asset variant in componentAssets[main]) for (final _Asset variant in variants)
variant.entryUri.path, variant.entryUri.path,
]; ];
} });
} }
} }
final List<_Asset> sortedKeys = jsonEntries.keys.toList() final List<_Asset> sortedKeys = jsonEntries.keys.toList()
...@@ -617,7 +623,7 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -617,7 +623,7 @@ class ManifestAssetBundle implements AssetBundle {
final Uri assetUri = fontAsset.assetUri; final Uri assetUri = fontAsset.assetUri;
if (assetUri.pathSegments.first == 'packages' && if (assetUri.pathSegments.first == 'packages' &&
!_fileSystem.isFileSync(_fileSystem.path.fromUri( !_fileSystem.isFileSync(_fileSystem.path.fromUri(
packageConfig[packageName].packageUriRoot.resolve('../${assetUri.path}')))) { packageConfig[packageName]?.packageUriRoot?.resolve('../${assetUri.path}')))) {
packageFontAssets.add(FontAsset( packageFontAssets.add(FontAsset(
fontAsset.assetUri, fontAsset.assetUri,
weight: fontAsset.weight, weight: fontAsset.weight,
...@@ -788,16 +794,17 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -788,16 +794,17 @@ class ManifestAssetBundle implements AssetBundle {
final Uri relativeUri = _fileSystem.path.toUri(relativePath); final Uri relativeUri = _fileSystem.path.toUri(relativePath);
final Uri entryUri = asset.symbolicPrefixUri == null final Uri entryUri = asset.symbolicPrefixUri == null
? relativeUri ? relativeUri
: asset.symbolicPrefixUri.resolveUri(relativeUri); : asset.symbolicPrefixUri?.resolveUri(relativeUri);
if (entryUri != null) {
variants.add( variants.add(
_Asset( _Asset(
baseDir: asset.baseDir, baseDir: asset.baseDir,
entryUri: entryUri, entryUri: entryUri,
relativeUri: relativeUri, relativeUri: relativeUri,
package: attributedPackage, package: attributedPackage,
), ),
); );
}
} }
result[asset] = variants; result[asset] = variants;
...@@ -862,9 +869,9 @@ class ManifestAssetBundle implements AssetBundle { ...@@ -862,9 +869,9 @@ class ManifestAssetBundle implements AssetBundle {
@immutable @immutable
class _Asset { class _Asset {
const _Asset({ const _Asset({
this.baseDir, @required this.baseDir,
this.relativeUri, @required this.relativeUri,
this.entryUri, @required this.entryUri,
@required this.package, @required this.package,
}); });
......
...@@ -64,8 +64,9 @@ class DevFSFileContent extends DevFSContent { ...@@ -64,8 +64,9 @@ class DevFSFileContent extends DevFSContent {
FileStat _fileStat; FileStat _fileStat;
File _getFile() { File _getFile() {
if (_linkTarget != null) { final File linkTarget = _linkTarget;
return _linkTarget; if (linkTarget != null) {
return linkTarget;
} }
if (file is Link) { if (file is Link) {
// The link target. // The link target.
...@@ -75,9 +76,10 @@ class DevFSFileContent extends DevFSContent { ...@@ -75,9 +76,10 @@ class DevFSFileContent extends DevFSContent {
} }
void _stat() { void _stat() {
if (_linkTarget != null) { final File linkTarget = _linkTarget;
if (linkTarget != null) {
// Stat the cached symlink target. // Stat the cached symlink target.
final FileStat fileStat = _linkTarget.statSync(); final FileStat fileStat = linkTarget.statSync();
if (fileStat.type == FileSystemEntityType.notFound) { if (fileStat.type == FileSystemEntityType.notFound) {
_linkTarget = null; _linkTarget = null;
} else { } else {
...@@ -87,7 +89,7 @@ class DevFSFileContent extends DevFSContent { ...@@ -87,7 +89,7 @@ class DevFSFileContent extends DevFSContent {
} }
final FileStat fileStat = file.statSync(); final FileStat fileStat = file.statSync();
_fileStat = fileStat.type == FileSystemEntityType.notFound ? null : fileStat; _fileStat = fileStat.type == FileSystemEntityType.notFound ? null : fileStat;
if (_fileStat != null && _fileStat.type == FileSystemEntityType.link) { if (_fileStat != null && _fileStat?.type == FileSystemEntityType.link) {
// Resolve, stat, and maybe cache the symlink target. // Resolve, stat, and maybe cache the symlink target.
final String resolved = file.resolveSymbolicLinksSync(); final String resolved = file.resolveSymbolicLinksSync();
final File linkTarget = file.fileSystem.file(resolved); final File linkTarget = file.fileSystem.file(resolved);
...@@ -96,7 +98,7 @@ class DevFSFileContent extends DevFSContent { ...@@ -96,7 +98,7 @@ class DevFSFileContent extends DevFSContent {
if (fileStat.type == FileSystemEntityType.notFound) { if (fileStat.type == FileSystemEntityType.notFound) {
_fileStat = null; _fileStat = null;
_linkTarget = null; _linkTarget = null;
} else if (devFSConfig.cacheSymlinks) { } else if (devFSConfig?.cacheSymlinks == true) {
_linkTarget = linkTarget; _linkTarget = linkTarget;
} }
} }
...@@ -104,25 +106,27 @@ class DevFSFileContent extends DevFSContent { ...@@ -104,25 +106,27 @@ class DevFSFileContent extends DevFSContent {
@override @override
bool get isModified { bool get isModified {
final FileStat _oldFileStat = _fileStat; final FileStat oldFileStat = _fileStat;
_stat(); _stat();
if (_oldFileStat == null && _fileStat == null) { final FileStat newFileStat = _fileStat;
if (oldFileStat == null && newFileStat == null) {
return false; return false;
} }
return _oldFileStat == null || _fileStat == null || _fileStat.modified.isAfter(_oldFileStat.modified); return oldFileStat == null || newFileStat == null || newFileStat.modified.isAfter(oldFileStat.modified);
} }
@override @override
bool isModifiedAfter(DateTime time) { bool isModifiedAfter(DateTime time) {
final FileStat _oldFileStat = _fileStat; final FileStat oldFileStat = _fileStat;
_stat(); _stat();
if (_oldFileStat == null && _fileStat == null) { final FileStat newFileStat = _fileStat;
if (oldFileStat == null && newFileStat == null) {
return false; return false;
} }
return time == null return time == null
|| _oldFileStat == null || oldFileStat == null
|| _fileStat == null || newFileStat == null
|| _fileStat.modified.isAfter(time); || newFileStat.modified.isAfter(time);
} }
@override @override
...@@ -135,7 +139,7 @@ class DevFSFileContent extends DevFSContent { ...@@ -135,7 +139,7 @@ class DevFSFileContent extends DevFSContent {
} }
@override @override
Future<List<int>> contentsAsBytes() => _getFile().readAsBytes(); Future<List<int>> contentsAsBytes() async => _getFile().readAsBytes();
@override @override
Stream<List<int>> contentsAsStream() => _getFile().openRead(); Stream<List<int>> contentsAsStream() => _getFile().openRead();
...@@ -308,8 +312,8 @@ class _DevFSHttpWriter implements DevFSWriter { ...@@ -308,8 +312,8 @@ class _DevFSHttpWriter implements DevFSWriter {
static const int kMaxInFlight = 3; static const int kMaxInFlight = 3;
int _inFlight = 0; int _inFlight = 0;
Map<Uri, DevFSContent> _outstanding; Map<Uri, DevFSContent> _outstanding = <Uri, DevFSContent>{};
Completer<void> _completer; Completer<void> _completer = Completer<void>();
@override @override
Future<void> write(Map<Uri, DevFSContent> entries, Uri devFSBase, [DevFSWriter parent]) async { Future<void> write(Map<Uri, DevFSContent> entries, Uri devFSBase, [DevFSWriter parent]) async {
...@@ -553,8 +557,9 @@ class DevFS { ...@@ -553,8 +557,9 @@ class DevFS {
/// If any other changes were made, or there is an error scanning the file, /// If any other changes were made, or there is an error scanning the file,
/// return `null`. /// return `null`.
String _checkIfSingleWidgetReloadApplied() { String _checkIfSingleWidgetReloadApplied() {
if (_widgetCacheOutputFile != null && _widgetCacheOutputFile.existsSync()) { final File widgetCacheOutputFile = _widgetCacheOutputFile;
final String widget = _widgetCacheOutputFile.readAsStringSync().trim(); if (widgetCacheOutputFile != null && widgetCacheOutputFile.existsSync()) {
final String widget = widgetCacheOutputFile.readAsStringSync().trim();
if (widget.isNotEmpty) { if (widget.isNotEmpty) {
return widget; return widget;
} }
......
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