mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
[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:
parent
a204f038fc
commit
91437a0641
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue