Skip to content

Commit d02e720

Browse files
authored
Improves workaround for MacOS file watching quirks (#47926)
1 parent bd0f283 commit d02e720

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,22 @@ async Task<ImmutableList<ChangedFile>> CaptureChangedFilesSnapshot(ImmutableDict
407407
var changedFiles = NormalizePathChanges(changedPaths)
408408
.Select(changedPath =>
409409
{
410+
// On macOS may report Update followed by Add when a new file is created or just updated.
411+
// We normalize Update + Add to just Add and Update + Add + Delete to Update above.
412+
// To distinguish between an addition and an update we check if the file exists.
413+
410414
if (evaluationResult.Files.TryGetValue(changedPath.Path, out var existingFileItem))
411415
{
412-
// On macOS may report Update followed by Add when a new file is created or just updated.
413-
// We normalize Update + Add to just Add above.
414-
// To distinguish between an addition and an update we check if the file exists.
415416
var changeKind = changedPath.Kind == ChangeKind.Add ? ChangeKind.Update : changedPath.Kind;
416417

417418
return new ChangedFile(existingFileItem, changeKind);
418419
}
419420

421+
// Do not assume the change is an addition, even if the file doesn't exist in the evaluation result.
422+
// The file could have been deleted and Add + Delete sequence could have been normalized to Update.
420423
return new ChangedFile(
421424
new FileItem() { FilePath = changedPath.Path, ContainingProjectPaths = [] },
422-
ChangeKind.Add);
425+
changedPath.Kind);
423426
})
424427
.ToImmutableList();
425428

0 commit comments

Comments
 (0)