Unverified Commit ed85dd49 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] use try to delete in web cache (#82478)

parent 0f8a6ab4
......@@ -183,9 +183,7 @@ class FlutterWebSdk extends CachedArtifact {
platformName += 'windows-x64';
}
final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/$platformName.zip');
if (location.existsSync()) {
location.deleteSync(recursive: true);
}
ErrorHandlingFileSystem.deleteIfExists(location, recursive: true);
await artifactUpdater.downloadZipArchive('Downloading Web SDK...', url, location);
// This is a temporary work-around for not being able to safely download into a shared directory.
final FileSystem fileSystem = location.fileSystem;
......
......@@ -745,6 +745,29 @@ void main() {
expect(webStuff.childFile('bar'), isNot(exists));
});
testWithoutContext('FlutterWebSdk uses tryToDelete to handle directory edge cases', () async {
final FileExceptionHandler handler = FileExceptionHandler();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
final Directory webStuff = fileSystem.directory('web-stuff');
final MockCache cache = MockCache();
final MockArtifactUpdater artifactUpdater = MockArtifactUpdater();
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform(operatingSystem: 'linux'));
when(cache.getWebSdkDirectory()).thenReturn(webStuff);
when(artifactUpdater.downloadZipArchive('Downloading Web SDK...', any, any))
.thenAnswer((Invocation invocation) async {
final Directory location = invocation.positionalArguments[2] as Directory;
location.createSync(recursive: true);
location.childFile('foo').createSync();
});
webStuff.childFile('bar').createSync(recursive: true);
handler.addError(webStuff, FileSystemOp.delete, const FileSystemException('', '', OSError('', 2)));
await expectLater(() => webSdk.updateInner(artifactUpdater, fileSystem, MockOperatingSystemUtils()), throwsToolExit(
message: RegExp('The Flutter tool tried to delete the file or directory web-stuff but was unable to'),
));
});
testWithoutContext('Cache handles exception thrown if stamp file cannot be parsed', () {
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
final FileSystem fileSystem = MemoryFileSystem.test(opHandle: exceptionHandler.opHandle);
......
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