[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.
This commit is contained in:
Jonah Williams 2021-01-27 12:56:21 -08:00 committed by GitHub
parent a204f038fc
commit 91437a0641
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -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 {

View file

@ -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();