[flutter_tool] Don't crash on failed stamp file update (#49080)
This commit is contained in:
committed by
Flutter GitHub Bot
parent
b67d5ec6e9
commit
dc94e479d1
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user