Commit dc94e479 authored by Zachary Anderson's avatar Zachary Anderson Committed by Flutter GitHub Bot

[flutter_tool] Don't crash on failed stamp file update (#49080)

parent b67d5ec6
......@@ -511,7 +511,16 @@ abstract class CachedArtifact extends ArtifactSet {
}
}
await updateInner();
cache.setStampFor(stampName, version);
try {
cache.setStampFor(stampName, version);
} on FileSystemException catch (err) {
globals.printError(
'The new artifact "$name" was downloaded, but Flutter failed to update '
'its stamp file, receiving the error "$err". '
'Flutter can continue, but the artifact may be re-downloaded on '
'subsequent invocations until the problem is resolved.',
);
}
_removeDownloadedFiles();
}
......
......@@ -115,6 +115,23 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Continues on failed stamp file update', () async {
final Directory artifactDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_artifact.');
final Directory downloadDir = globals.fs.systemTempDirectory.createTempSync('flutter_cache_test_download.');
when(mockCache.getArtifactDirectory(any)).thenReturn(artifactDir);
when(mockCache.getDownloadDir()).thenReturn(downloadDir);
when(mockCache.setStampFor(any, any)).thenAnswer((_) {
throw const FileSystemException('stamp write failed');
});
final FakeSimpleArtifact artifact = FakeSimpleArtifact(mockCache);
await artifact.update();
expect(testLogger.errorText, contains('stamp write failed'));
}, overrides: <Type, Generator>{
Cache: () => mockCache,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Gradle wrapper should not be up to date, if some cached artifact is not available', () {
final GradleWrapper gradleWrapper = GradleWrapper(mockCache);
final Directory directory = globals.fs.directory('/Applications/flutter/bin/cache');
......@@ -455,6 +472,19 @@ class FakeCachedArtifact extends EngineCachedArtifact {
List<String> getPackageDirs() => packageDirs;
}
class FakeSimpleArtifact extends CachedArtifact {
FakeSimpleArtifact(Cache cache) : super(
'fake',
cache,
DevelopmentArtifact.universal,
);
@override
Future<void> updateInner() async {
// nop.
}
}
class FakeDownloadedArtifact extends CachedArtifact {
FakeDownloadedArtifact(this.downloadedFile, Cache cache) : super(
'fake',
......
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