Unverified Commit 91437a06 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] delete old directories when unzipping ontop of them (#74818)

Fixes #74772

stale files from previous SDKs were getting left in the cache, confusing the analyzer.
parent a204f038
......@@ -1789,6 +1789,12 @@ class ArtifactUpdater {
} finally {
status.stop();
}
/// Unzipping multiple file into a directory will not remove old files
/// from previous versions that are not present in the new bundle.
final Directory destination = location.childDirectory(
tempFile.fileSystem.path.basenameWithoutExtension(tempFile.path)
);
ErrorHandlingFileSystem.deleteIfExists(destination, recursive: true);
_ensureExists(location);
try {
......
......@@ -44,6 +44,35 @@ void main() {
expect(fileSystem.file('out/test'), exists);
});
testWithoutContext('ArtifactUpdater can download a zip archive and delete stale files', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
fileSystem: fileSystem,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
platform: testPlatform,
httpClient: MockHttpClient(),
tempStorage: fileSystem.currentDirectory.childDirectory('temp')
..createSync(),
);
// Unrelated file from another cache.
fileSystem.file('out/bar').createSync(recursive: true);
// Stale file from current cache.
fileSystem.file('out/test/foo.txt').createSync(recursive: true);
await artifactUpdater.downloadZipArchive(
'test message',
Uri.parse('http:///test.zip'),
fileSystem.currentDirectory.childDirectory('out'),
);
expect(logger.statusText, contains('test message'));
expect(fileSystem.file('out/test'), exists);
expect(fileSystem.file('out/bar'), exists);
expect(fileSystem.file('out/test/foo.txt'), isNot(exists));
});
testWithoutContext('ArtifactUpdater will not validate the md5 hash if the '
'x-goog-hash header is present but missing an md5 entry', () async {
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
......
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