|
5 | 5 | using System.Collections.Concurrent;
|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using System.IO;
|
| 8 | +using System.Security; |
8 | 9 | using System.Threading;
|
9 | 10 | using System.Threading.Tasks;
|
10 | 11 | using Microsoft.Extensions.FileSystemGlobbing;
|
@@ -129,13 +130,24 @@ private void OnRenamed(object sender, RenamedEventArgs e)
|
129 | 130 |
|
130 | 131 | if (Directory.Exists(e.FullPath))
|
131 | 132 | {
|
132 |
| - // If the renamed entity is a directory then notify tokens for every sub item. |
133 |
| - foreach (var newLocation in Directory.EnumerateFileSystemEntries(e.FullPath, "*", SearchOption.AllDirectories)) |
| 133 | + try |
| 134 | + { |
| 135 | + // If the renamed entity is a directory then notify tokens for every sub item. |
| 136 | + foreach (var newLocation in Directory.EnumerateFileSystemEntries(e.FullPath, "*", SearchOption.AllDirectories)) |
| 137 | + { |
| 138 | + // Calculated previous path of this moved item. |
| 139 | + var oldLocation = Path.Combine(e.OldFullPath, newLocation.Substring(e.FullPath.Length + 1)); |
| 140 | + OnFileSystemEntryChange(oldLocation); |
| 141 | + OnFileSystemEntryChange(newLocation); |
| 142 | + } |
| 143 | + } |
| 144 | + catch (Exception ex) when ( |
| 145 | + ex is IOException || |
| 146 | + ex is SecurityException || |
| 147 | + ex is DirectoryNotFoundException || |
| 148 | + ex is UnauthorizedAccessException) |
134 | 149 | {
|
135 |
| - // Calculated previous path of this moved item. |
136 |
| - var oldLocation = Path.Combine(e.OldFullPath, newLocation.Substring(e.FullPath.Length + 1)); |
137 |
| - OnFileSystemEntryChange(oldLocation); |
138 |
| - OnFileSystemEntryChange(newLocation); |
| 150 | + // Swallow the exception. |
139 | 151 | }
|
140 | 152 | }
|
141 | 153 | }
|
|
0 commit comments