From b05d6ec8d3b91b552e69cc937319a37a6b10bec9 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 10 Feb 2021 17:04:32 -0800 Subject: [PATCH] [flutter_tools] catch error 32 in cache (#75719) --- packages/flutter_tools/lib/src/cache.dart | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 8cdd95d2ab..fe751d7eb6 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -1796,7 +1796,24 @@ class ArtifactUpdater { final Directory destination = location.childDirectory( tempFile.fileSystem.path.basenameWithoutExtension(tempFile.path) ); - ErrorHandlingFileSystem.deleteIfExists(destination, recursive: true); + try { + ErrorHandlingFileSystem.deleteIfExists( + destination, + recursive: true, + ); + } on FileSystemException catch (error) { + // Error that indicates another program has this file open and that it + // cannot be deleted. For the cache, this is either the analyzer reading + // the sky_engine package or a running flutter_tester device. + const int kSharingViolation = 32; + if (_platform.isWindows && error.osError.errorCode == kSharingViolation) { + throwToolExit( + 'Failed to delete ${destination.path} because the local file/directory is in use ' + 'by another process. Try closing any running IDEs or editors and trying ' + 'again' + ); + } + } _ensureExists(location); try {