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 {