@@ -620,9 +620,9 @@ internal static void ConfigureLoggerFactory(ScriptHostConfiguration scriptConfig
620
620
scriptConfig . LoggerFactoryBuilder . AddLoggerProviders ( scriptConfig . HostConfig . LoggerFactory , scriptConfig , settingsManager ) ;
621
621
}
622
622
623
- private void TraceFileChangeRestart ( string changeType , string path , bool isShutdown )
623
+ private void TraceFileChangeRestart ( string changeDescription , string changeType , string path , bool isShutdown )
624
624
{
625
- string fileChangeMsg = string . Format ( CultureInfo . InvariantCulture , "File change of type '{0 }' detected for '{1 }'" , changeType , path ) ;
625
+ string fileChangeMsg = string . Format ( CultureInfo . InvariantCulture , "{0} change of type '{1 }' detected for '{2 }'" , changeDescription , changeType , path ) ;
626
626
TraceWriter . Info ( fileChangeMsg ) ;
627
627
Logger ? . LogInformation ( fileChangeMsg ) ;
628
628
@@ -1619,40 +1619,45 @@ private void NotifyInvoker(string functionName, Exception ex)
1619
1619
1620
1620
private void OnFileChanged ( FileSystemEventArgs e )
1621
1621
{
1622
- string directory = GetRelativeDirectory ( e . FullPath , ScriptConfig . RootScriptPath ) ;
1623
- bool isWatchedDirectory = ScriptConfig . WatchDirectories . Contains ( directory ) ;
1624
-
1625
1622
// We will perform a host restart in the following cases:
1626
1623
// - the file change was under one of the configured watched directories (e.g. node_modules, shared code directories, etc.)
1627
1624
// - the host.json file was changed
1628
1625
// - a function.json file was changed
1626
+ // - a proxies.json file was changed
1629
1627
// - a function directory was added/removed/renamed
1630
1628
// A full host shutdown is performed when an assembly (.dll, .exe) in a watched directory is modified
1629
+
1630
+ string changeDescription = string . Empty ;
1631
+ string directory = GetRelativeDirectory ( e . FullPath , ScriptConfig . RootScriptPath ) ;
1631
1632
string fileName = Path . GetFileName ( e . Name ) ;
1632
- if ( isWatchedDirectory ||
1633
- ( string . Compare ( fileName , ScriptConstants . HostMetadataFileName , StringComparison . OrdinalIgnoreCase ) == 0 ||
1634
- string . Compare ( fileName , ScriptConstants . FunctionMetadataFileName , StringComparison . OrdinalIgnoreCase ) == 0 ||
1635
- string . Compare ( fileName , ScriptConstants . ProxyMetadataFileName , StringComparison . OrdinalIgnoreCase ) == 0 ) ||
1636
- ! _directorySnapshot . SequenceEqual ( Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) ) )
1637
- {
1638
- // CRI ICM: 46695121
1639
- // Do not allow the host to restart if this notification is for the hostingstart.html file in the root
1640
- if ( string . Compare ( directory , "hostingstart.html" , StringComparison . OrdinalIgnoreCase ) == 0 )
1641
- {
1642
- string hostingWarning = string . Format ( CultureInfo . InvariantCulture , "Unexpected file change event detected for '{0}' which evaluated to a host restart. Suppressing restart." , e . FullPath ) ;
1643
- TraceWriter . Warning ( hostingWarning ) ;
1644
- Logger ? . LogWarning ( hostingWarning ) ;
1645
- return ;
1646
- }
1647
1633
1634
+ if ( ScriptConfig . WatchDirectories . Contains ( directory ) )
1635
+ {
1636
+ changeDescription = "Watched directory" ;
1637
+ }
1638
+ else if ( string . Compare ( fileName , ScriptConstants . HostMetadataFileName , StringComparison . OrdinalIgnoreCase ) == 0 ||
1639
+ string . Compare ( fileName , ScriptConstants . FunctionMetadataFileName , StringComparison . OrdinalIgnoreCase ) == 0 ||
1640
+ string . Compare ( fileName , ScriptConstants . ProxyMetadataFileName , StringComparison . OrdinalIgnoreCase ) == 0 )
1641
+ {
1642
+ changeDescription = "File" ;
1643
+ }
1644
+ else if ( ( e . ChangeType == WatcherChangeTypes . Deleted || Directory . Exists ( e . FullPath ) )
1645
+ && ! _directorySnapshot . SequenceEqual ( Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) ) )
1646
+ {
1647
+ // Check directory spashot only if "Deleted" change or if directory changed
1648
+ changeDescription = "Directory" ;
1649
+ }
1650
+
1651
+ if ( ! string . IsNullOrEmpty ( changeDescription ) )
1652
+ {
1648
1653
bool shutdown = false ;
1649
1654
string fileExtension = Path . GetExtension ( fileName ) ;
1650
1655
if ( ! string . IsNullOrEmpty ( fileExtension ) && ScriptConstants . AssemblyFileTypes . Contains ( fileExtension , StringComparer . OrdinalIgnoreCase ) )
1651
1656
{
1652
1657
shutdown = true ;
1653
1658
}
1654
1659
1655
- TraceFileChangeRestart ( e . ChangeType . ToString ( ) , e . FullPath , shutdown ) ;
1660
+ TraceFileChangeRestart ( changeDescription , e . ChangeType . ToString ( ) , e . FullPath , shutdown ) ;
1656
1661
ScheduleRestartAsync ( shutdown ) . ContinueWith ( t => TraceWriter . Error ( $ "Error restarting host (full shutdown: { shutdown } )", t . Exception ) ,
1657
1662
TaskContinuationOptions . ExecuteSynchronously | TaskContinuationOptions . OnlyOnFaulted ) ;
1658
1663
}
0 commit comments