Be more resiliant to apphost.config issues (#1044)

This commit is contained in:
Justin Kotalik 2018-07-12 09:45:51 -07:00 committed by GitHub
parent c81f379045
commit ba599c49bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -199,9 +199,20 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
e => _logger.LogWarning($"Failed to delete file : {e.Message}"));
}
RetryFileOperation(
() => File.Move(_apphostConfigBackupPath, _apphostConfigPath),
e => _logger.LogError($"Failed to backup apphost.config: {e.Message}"));
if (File.Exists(_apphostConfigBackupPath))
{
RetryFileOperation(
() => File.Move(_apphostConfigBackupPath, _apphostConfigPath),
e => _logger.LogError($"Failed to backup apphost.config: {e.Message}"));
}
else
{
// Test failed to create backup config file, put a default one from IIS.config there instead.
// An apphost.config file is required to be replaced because we use it for removing the app pool.
RetryFileOperation(
() => File.WriteAllText(_apphostConfigPath, File.ReadAllText("IIS.config")),
e => _logger.LogWarning($"Failed to copy IIS.config to apphost.config: {e.Message}"));
}
_logger.LogInformation($"Restored {_apphostConfigPath}.");
}