diff options
| author | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-03-08 15:46:13 +0100 |
|---|---|---|
| committer | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-03-08 15:46:13 +0100 |
| commit | 8dbb1c92573ba5cf3e4f8d953ffd6083a8ccbde4 (patch) | |
| tree | cbcaa602a9f95b296f26c4026bbf611701018863 /Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs | |
| parent | 2f0b4cc24c84d98820c8a6755191d4fc1dab74e7 (diff) | |
Use logging.json instead of logging.user.json for override settings
Diffstat (limited to 'Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs')
| -rw-r--r-- | Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs index 6dbeb2776..834099ea0 100644 --- a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs +++ b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs @@ -16,11 +16,6 @@ namespace Jellyfin.Server.Migrations.Routines internal class CreateUserLoggingConfigFile : IMigrationRoutine { /// <summary> - /// An empty logging JSON configuration, which will be used as the default contents for the user settings config file. - /// </summary> - private const string EmptyLoggingConfig = @"{ ""Serilog"": { } }"; - - /// <summary> /// File history for logging.json as existed during this migration creation. The contents for each has been minified. /// </summary> private readonly List<string> _defaultConfigHistory = new List<string> @@ -48,46 +43,28 @@ namespace Jellyfin.Server.Migrations.Routines public void Perform(CoreAppHost host, ILogger logger) { var logDirectory = host.Resolve<IApplicationPaths>().ConfigurationDirectoryPath; - var oldConfigPath = Path.Combine(logDirectory, "logging.json"); - var userConfigPath = Path.Combine(logDirectory, Program.LoggingConfigFileUser); + var existingConfigPath = Path.Combine(logDirectory, "logging.json"); - // Check if there are existing settings in the old "logging.json" file that should be migrated - bool shouldMigrateOldFile = ShouldKeepOldConfig(oldConfigPath); - - // Create the user settings file "logging.user.json" - if (shouldMigrateOldFile) - { - // Use the existing logging.json file - File.Copy(oldConfigPath, userConfigPath); - } - else + // If the existing logging.json config file is unmodified, then 'reset' it by moving it to 'logging.old.json' + // NOTE: This config file has 'reloadOnChange: true', so this change will take effect immediately even though it has already been loaded + if (File.Exists(existingConfigPath) && ExistingConfigUnmodified(existingConfigPath)) { - // Write an empty JSON file - File.WriteAllText(userConfigPath, EmptyLoggingConfig); + File.Move(existingConfigPath, Path.Combine(logDirectory, "logging.old.json")); } } /// <summary> - /// Check if the existing logging.json file should be migrated to logging.user.json. + /// Check if the existing logging.json file has not been modified by the user by comparing it to all the + /// versions in our git history. Until now, the file has never been migrated after first creation so users + /// could have any version from the git history. /// </summary> - private bool ShouldKeepOldConfig(string oldConfigPath) + /// <exception cref="IOException"><paramref name="oldConfigPath"/> does not exist or could not be read.</exception> + private bool ExistingConfigUnmodified(string oldConfigPath) { - // Cannot keep the old logging file if it doesn't exist - if (!File.Exists(oldConfigPath)) - { - return false; - } - - // Check if the existing logging.json file has been modified by the user by comparing it to all the - // versions in our git history. Until now, the file has never been migrated after first creation so users - // could have any version from the git history. var existingConfigJson = JToken.Parse(File.ReadAllText(oldConfigPath)); - var existingConfigIsUnmodified = _defaultConfigHistory + return _defaultConfigHistory .Select(historicalConfigText => JToken.Parse(historicalConfigText)) .Any(historicalConfigJson => JToken.DeepEquals(existingConfigJson, historicalConfigJson)); - - // The existing config file should be kept and used only if it has been modified by the user - return !existingConfigIsUnmodified; } } } |
