diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index ac5e45d626..069d5b5682 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -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(); } diff --git a/packages/flutter_tools/test/general.shard/cache_test.dart b/packages/flutter_tools/test/general.shard/cache_test.dart index c0aaf67f81..43a007a093 100644 --- a/packages/flutter_tools/test/general.shard/cache_test.dart +++ b/packages/flutter_tools/test/general.shard/cache_test.dart @@ -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: { + 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 getPackageDirs() => packageDirs; } +class FakeSimpleArtifact extends CachedArtifact { + FakeSimpleArtifact(Cache cache) : super( + 'fake', + cache, + DevelopmentArtifact.universal, + ); + + @override + Future updateInner() async { + // nop. + } +} + class FakeDownloadedArtifact extends CachedArtifact { FakeDownloadedArtifact(this.downloadedFile, Cache cache) : super( 'fake',