Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #9983 MigrateNetworkConfiguration error #9987

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Jellyfin.Server/Migrations/MigrationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void RunPreStartup(ServerApplicationPaths appPaths, ILoggerFactory

private static void HandleStartupWizardCondition(IEnumerable<IMigrationRoutine> migrations, MigrationOptions migrationOptions, bool isStartWizardCompleted, ILogger logger)
{
if (isStartWizardCompleted || migrationOptions.Applied.Count != 0)
if (isStartWizardCompleted)
{
return;
}
Expand All @@ -106,6 +106,8 @@ private static void HandleStartupWizardCondition(IEnumerable<IMigrationRoutine>

private static void PerformMigrations(IMigrationRoutine[] migrations, MigrationOptions migrationOptions, Action<MigrationOptions> saveConfiguration, ILogger logger)
{
// save already applied migrations, and skip them thereafter
saveConfiguration(migrationOptions);
var appliedMigrationIds = migrationOptions.Applied.Select(m => m.Id).ToHashSet();

for (var i = 0; i < migrations.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
Expand Down Expand Up @@ -39,8 +39,23 @@ public void Perform()
{
string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "network.xml");
var oldNetworkConfigSerializer = new XmlSerializer(typeof(OldNetworkConfiguration), new XmlRootAttribute("NetworkConfiguration"));
using var xmlReader = XmlReader.Create(path);
var oldNetworkConfiguration = (OldNetworkConfiguration?)oldNetworkConfigSerializer.Deserialize(xmlReader);
OldNetworkConfiguration? oldNetworkConfiguration = null;

try
{
using (var xmlReader = XmlReader.Create(path))
{
oldNetworkConfiguration = (OldNetworkConfiguration?)oldNetworkConfigSerializer.Deserialize(xmlReader);
}
}
catch (InvalidOperationException ex)
{
_logger.LogError(ex, "Migrate NetworkConfiguration deserialize Invalid Operation error");
}
catch (Exception ex)
{
_logger.LogError(ex, "Migrate NetworkConfiguration deserialize error");
}

if (oldNetworkConfiguration is not null)
{
Expand Down Expand Up @@ -82,8 +97,10 @@ public void Perform()

var networkConfigSerializer = new XmlSerializer(typeof(NetworkConfiguration));
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
networkConfigSerializer.Serialize(xmlWriter, networkConfiguration);
using (var xmlWriter = XmlWriter.Create(path, xmlWriterSettings))
{
networkConfigSerializer.Serialize(xmlWriter, networkConfiguration);
}
}
}

Expand Down
Loading