Skip to content

Commit 5fd4f87

Browse files
Avoid crashing in PollingFileWatcher (#21544)
1 parent a9d7026 commit 5fd4f87

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -188,7 +188,17 @@ private void ForeachEntityInDirectory(DirectoryInfo dirInfo, Action<FileSystemIn
188188
return;
189189
}
190190

191-
var entities = dirInfo.EnumerateFileSystemInfos("*.*");
191+
IEnumerable<FileSystemInfo> entities;
192+
try
193+
{
194+
entities = dirInfo.EnumerateFileSystemInfos("*.*");
195+
}
196+
// If the directory is deleted after the exists check this will throw and could crash the process
197+
catch (DirectoryNotFoundException)
198+
{
199+
return;
200+
}
201+
192202
foreach (var entity in entities)
193203
{
194204
fileAction(entity);

0 commit comments

Comments
 (0)