Skip to content

Commit

Permalink
Merge pull request jellyfin#9987 from Sky-High/fix-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 authored Jul 15, 2023
2 parents ce2520e + 06b80a8 commit 9de667f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
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

0 comments on commit 9de667f

Please sign in to comment.