From 9b71912dc6423510fee9dd4c73ead24647506176 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Wed, 6 May 2020 11:14:05 -0700 Subject: [PATCH] Avoid crashing in PollingFileWatcher --- .../src/Internal/FileWatcher/PollingFileWatcher.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs b/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs index 1b503af7749f..023b75a1b734 100644 --- a/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs +++ b/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -188,7 +188,17 @@ private void ForeachEntityInDirectory(DirectoryInfo dirInfo, Action entities; + try + { + entities = dirInfo.EnumerateFileSystemInfos("*.*"); + } + // If the directory is deleted after the exists check this will throw and could crash the process + catch (DirectoryNotFoundException) + { + return; + } + foreach (var entity in entities) { fileAction(entity);