From a7f7687a2e207cfc87146fb27ab7ab507228cf63 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 4 Mar 2021 19:36:21 -0800 Subject: [PATCH] Delete unzipped FlutterMacOS.framework before replacing artifact (#77316) --- packages/flutter_tools/lib/src/cache.dart | 1 + .../test/general.shard/cache_test.dart | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 60a4c56446..738d4559b3 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -934,6 +934,7 @@ abstract class EngineCachedArtifact extends CachedArtifact { final File frameworkZip = fileSystem.file(fileSystem.path.join(dir.path, 'FlutterMacOS.framework.zip')); if (frameworkZip.existsSync()) { final Directory framework = fileSystem.directory(fileSystem.path.join(dir.path, 'FlutterMacOS.framework')); + ErrorHandlingFileSystem.deleteIfExists(framework, recursive: true); framework.createSync(); operatingSystemUtils.unzip(frameworkZip, framework); } diff --git a/packages/flutter_tools/test/general.shard/cache_test.dart b/packages/flutter_tools/test/general.shard/cache_test.dart index aaf402ada2..6094ef4664 100644 --- a/packages/flutter_tools/test/general.shard/cache_test.dart +++ b/packages/flutter_tools/test/general.shard/cache_test.dart @@ -308,6 +308,33 @@ void main() { verify(operatingSystemUtils.chmod(argThat(hasPath(dir.path)), 'a+r,a+x')); }); + testWithoutContext('EngineCachedArtifact removes unzipped FlutterMacOS.framework before replacing', () async { + final OperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils(); + final MockCache cache = MockCache(); + final FileSystem fileSystem = MemoryFileSystem.test(); + final Directory artifactDir = fileSystem.systemTempDirectory.createTempSync('flutter_cache_test_artifact.'); + final Directory downloadDir = fileSystem.systemTempDirectory.createTempSync('flutter_cache_test_download.'); + + when(cache.getArtifactDirectory(any)).thenReturn(artifactDir); + when(cache.getDownloadDir()).thenReturn(downloadDir); + final Directory binDir = artifactDir.childDirectory('bin_dir')..createSync(); + binDir.childFile('FlutterMacOS.framework.zip').createSync(); + final Directory unzippedFramework = binDir.childDirectory('FlutterMacOS.framework'); + final File staleFile = unzippedFramework.childFile('stale_file')..createSync(recursive: true); + artifactDir.childFile('unused_url_path').createSync(); + + final FakeCachedArtifact artifact = FakeCachedArtifact( + cache: cache, + binaryDirs: >[ + ['bin_dir', 'unused_url_path'], + ], + requiredArtifacts: DevelopmentArtifact.universal, + ); + await artifact.updateInner(MockArtifactUpdater(), fileSystem, operatingSystemUtils); + expect(unzippedFramework, exists); + expect(staleFile, isNot(exists)); + }); + testWithoutContext('IosUsbArtifacts verifies executables for libimobiledevice in isUpToDateInner', () async { final FileSystem fileSystem = MemoryFileSystem.test(); final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any());