Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Dec 17, 2024
1 parent 394dc84 commit dfa2186
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ void FileChangedCallback(ChangedPath change)
break;
}

// If the changes include addition wait a little bit more for possible matching deletion.
// This eliminates reevaluations caused by teared temp file add/delete change pair.
if (!extendTimeout && changedFilesAccumulator.Any(change => change.Kind == ChangeKind.Add))
// If the changes include addition/deletion wait a little bit more for possible matching deletion/addition.
// This eliminates reevaluations caused by teared add + delete of a temp file or a move of a file.
if (!extendTimeout && changedFilesAccumulator.Any(change => change.Kind is ChangeKind.Add or ChangeKind.Delete))
{
extendTimeout = true;
continue;
Expand Down Expand Up @@ -689,6 +689,10 @@ internal static IEnumerable<ChangedPath> NormalizePathChanges(IEnumerable<Change
lastAdd = null;
lastUpdate ??= item with { Kind = ChangeKind.Update };
}
else
{
lastAdd = item;
}
}
else if (item.Kind == ChangeKind.Delete)
{
Expand Down Expand Up @@ -720,7 +724,16 @@ internal static IEnumerable<ChangedPath> NormalizePathChanges(IEnumerable<Change
}
}

return lastDelete ?? lastAdd ?? lastUpdate;
var result = lastDelete ?? lastAdd ?? lastUpdate;

// On macOS may report Update followed by Add when a new file is created.
// Convert any update
//if (result?.Kind == ChangeKind.Update && !fileExists(group.Key))
//{
// return new ChangedPath(group.Key, ChangeKind.Add);
//}

return result;
})
.Where(item => item != null)
.Select(item => item!.Value);
Expand Down
5 changes: 5 additions & 0 deletions src/BuiltInTools/dotnet-watch/Internal/FileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void WatchDirectories(IEnumerable<string> directories)
}

var newWatcher = FileWatcherFactory.CreateWatcher(directory);
if (newWatcher is EventBasedDirectoryWatcher eventBasedWatcher)
{
eventBasedWatcher.Logger = message => reporter.Verbose(message);
}

newWatcher.OnFileChange += WatcherChangedHandler;
newWatcher.OnError += WatcherErrorHandler;
newWatcher.EnableRaisingEvents = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dotnet-watch": {
"commandName": "Project",
"commandLineArgs": "--verbose /bl:DotnetRun.binlog",
"workingDirectory": "$(RepoRoot)src\\Assets\\TestProjects\\BlazorWasmWithLibrary\\blazorwasm",
"workingDirectory": "C:\\sdk1\\artifacts\\tmp\\Debug\\RenameDirecto---333D0BB9\\AppWithDeps",
"environmentVariables": {
"DOTNET_WATCH_DEBUG_SDK_DIRECTORY": "$(RepoRoot)artifacts\\bin\\redist\\$(Configuration)\\dotnet\\sdk\\$(Version)",
"DCP_IDE_REQUEST_TIMEOUT_SECONDS": "100000",
Expand Down

0 comments on commit dfa2186

Please sign in to comment.