Skip to content

Commit

Permalink
[flutter_tools] delete old directories when unzipping ontop of them (#…
Browse files Browse the repository at this point in the history
…74818)

Fixes #74772

stale files from previous SDKs were getting left in the cache, confusing the analyzer.
  • Loading branch information
jonahwilliams committed Jan 27, 2021
1 parent a204f03 commit 91437a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/flutter_tools/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 91437a0

Please sign in to comment.