From 04d1a53d199bbf5fced102daae77b3ef0d64474d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 29 Dec 2013 12:07:29 -0500 Subject: [PATCH] don't persist lazy loaded paths --- MediaBrowser.Api/SystemService.cs | 6 +- .../BaseApplicationPaths.cs | 13 +--- .../Configuration/BaseConfigurationManager.cs | 6 +- .../ScheduledTasks/ScheduledTaskWorker.cs | 40 ++++-------- .../Security/MBLicenseFile.cs | 20 ++++-- MediaBrowser.Controller/Entities/User.cs | 63 +++++-------------- MediaBrowser.Mono.userprefs | 5 +- .../MediaInfo/FFProbeVideoInfoProvider.cs | 2 +- MediaBrowser.Server.Mono/app.config | 3 +- MediaBrowser.ServerApplication/App.config | 3 +- .../ApplicationHost.cs | 3 +- .../MediaBrowser.WebDashboard.csproj | 42 ------------- 12 files changed, 61 insertions(+), 145 deletions(-) diff --git a/MediaBrowser.Api/SystemService.cs b/MediaBrowser.Api/SystemService.cs index dae603dc89..23d64e89b5 100644 --- a/MediaBrowser.Api/SystemService.cs +++ b/MediaBrowser.Api/SystemService.cs @@ -124,9 +124,11 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetConfiguration request) { - var dateModified = _fileSystem.GetLastWriteTimeUtc(_configurationManager.ApplicationPaths.SystemConfigurationFilePath); + var configPath = _configurationManager.ApplicationPaths.SystemConfigurationFilePath; - var cacheKey = (_configurationManager.ApplicationPaths.SystemConfigurationFilePath + dateModified.Ticks).GetMD5(); + var dateModified = _fileSystem.GetLastWriteTimeUtc(configPath); + + var cacheKey = (configPath + dateModified.Ticks).GetMD5(); return ToOptimizedResultUsingCache(cacheKey, dateModified, null, () => _configurationManager.Configuration); } diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index 213942c9dc..668b1395d8 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -140,10 +140,6 @@ namespace MediaBrowser.Common.Implementations } } - /// - /// The _configuration directory path - /// - private string _configurationDirectoryPath; /// /// Gets the path to the application configuration root directory /// @@ -152,12 +148,7 @@ namespace MediaBrowser.Common.Implementations { get { - if (_configurationDirectoryPath == null) - { - _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config"); - Directory.CreateDirectory(_configurationDirectoryPath); - } - return _configurationDirectoryPath; + return Path.Combine(ProgramDataPath, "config"); } } @@ -218,7 +209,7 @@ namespace MediaBrowser.Common.Implementations /// System.String. private string GetProgramDataPath() { - var programDataPath = _useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : Path.Combine(ConfigurationManager.AppSettings["ReleaseProgramDataPath"], ConfigurationManager.AppSettings["ProgramDataFolderName"]); + var programDataPath = _useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : ConfigurationManager.AppSettings["ReleaseProgramDataPath"]; programDataPath = programDataPath.Replace("%ApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index 3c00673baa..8c4840ea71 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -99,9 +99,13 @@ namespace MediaBrowser.Common.Implementations.Configuration /// public void SaveConfiguration() { + var path = CommonApplicationPaths.SystemConfigurationFilePath; + + Directory.CreateDirectory(Path.GetDirectoryName(path)); + lock (_configurationSaveLock) { - XmlSerializer.SerializeToFile(CommonConfiguration, CommonApplicationPaths.SystemConfigurationFilePath); + XmlSerializer.SerializeToFile(CommonConfiguration, path); } OnConfigurationUpdated(); diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 2406d0470e..477dc4aee5 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { LazyInitializer.EnsureInitialized(ref _lastExecutionResult, ref _lastExecutionResultinitialized, ref _lastExecutionResultSyncLock, () => { - var path = GetHistoryFilePath(false); + var path = GetHistoryFilePath(); try { @@ -432,43 +432,28 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// /// Gets the scheduled tasks configuration directory. /// - /// if set to true [create]. /// System.String. - private string GetScheduledTasksConfigurationDirectory(bool create) + private string GetScheduledTasksConfigurationDirectory() { - var path = Path.Combine(ApplicationPaths.ConfigurationDirectoryPath, "ScheduledTasks"); - - if (create) - { - Directory.CreateDirectory(path); - } - - return path; + return Path.Combine(ApplicationPaths.ConfigurationDirectoryPath, "ScheduledTasks"); } /// /// Gets the scheduled tasks data directory. /// - /// if set to true [create]. /// System.String. - private string GetScheduledTasksDataDirectory(bool create) + private string GetScheduledTasksDataDirectory() { - var path = Path.Combine(ApplicationPaths.DataPath, "ScheduledTasks"); - - if (create) - { - Directory.CreateDirectory(path); - } - return path; + return Path.Combine(ApplicationPaths.DataPath, "ScheduledTasks"); } /// /// Gets the history file path. /// /// The history file path. - private string GetHistoryFilePath(bool createDirectory) + private string GetHistoryFilePath() { - return Path.Combine(GetScheduledTasksDataDirectory(createDirectory), Id + ".js"); + return Path.Combine(GetScheduledTasksDataDirectory(), Id + ".js"); } /// @@ -477,7 +462,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// System.String. private string GetConfigurationFilePath() { - return Path.Combine(GetScheduledTasksConfigurationDirectory(false), Id + ".js"); + return Path.Combine(GetScheduledTasksConfigurationDirectory(), Id + ".js"); } /// @@ -512,9 +497,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { var path = GetConfigurationFilePath(); - var parentPath = Path.GetDirectoryName(path); - - Directory.CreateDirectory(parentPath); + Directory.CreateDirectory(Path.GetDirectoryName(path)); JsonSerializer.SerializeToFile(triggers.Select(ScheduledTaskHelpers.GetTriggerInfo), path); } @@ -545,7 +528,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks result.ErrorMessage = ex.Message; } - JsonSerializer.SerializeToFile(result, GetHistoryFilePath(true)); + var path = GetHistoryFilePath(); + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + JsonSerializer.SerializeToFile(result, path); LastExecutionResult = result; diff --git a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs index 163a368bfb..c5d5f28d60 100644 --- a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs +++ b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs @@ -11,7 +11,6 @@ namespace MediaBrowser.Common.Implementations.Security { private readonly IApplicationPaths _appPaths; - private readonly string _filename; public string RegKey { get { return _regKey; } @@ -26,6 +25,14 @@ namespace MediaBrowser.Common.Implementations.Security } } + private string Filename + { + get + { + return Path.Combine(_appPaths.ConfigurationDirectoryPath, "mb.lic"); + } + } + public string LegacyKey { get; set; } private Dictionary UpdateRecords { get; set; } private readonly object _lck = new object(); @@ -35,8 +42,6 @@ namespace MediaBrowser.Common.Implementations.Security { _appPaths = appPaths; - _filename = Path.Combine(_appPaths.ConfigurationDirectoryPath, "mb.lic"); - UpdateRecords = new Dictionary(); Load(); } @@ -64,15 +69,16 @@ namespace MediaBrowser.Common.Implementations.Security private void Load() { string[] contents = null; + var licenseFile = Filename; lock (_lck) { try { - contents = File.ReadAllLines(_filename); + contents = File.ReadAllLines(licenseFile); } catch (FileNotFoundException) { - (File.Create(_filename)).Close(); + (File.Create(licenseFile)).Close(); } } if (contents != null && contents.Length > 0) @@ -100,7 +106,9 @@ namespace MediaBrowser.Common.Implementations.Security lines.Add(pair.Value.Ticks.ToString()); } - lock(_lck) File.WriteAllLines(_filename, lines); + var licenseFile = Filename; + Directory.CreateDirectory(Path.GetDirectoryName(licenseFile)); + lock (_lck) File.WriteAllLines(licenseFile, lines); } } } diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index 0a935cd0de..466e709dd0 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -76,14 +76,6 @@ namespace MediaBrowser.Controller.Entities /// private UserRootFolder _rootFolder; /// - /// The _user root folder initialized - /// - private bool _userRootFolderInitialized; - /// - /// The _user root folder sync lock - /// - private object _userRootFolderSyncLock = new object(); - /// /// Gets the root folder. /// /// The root folder. @@ -92,17 +84,11 @@ namespace MediaBrowser.Controller.Entities { get { - LazyInitializer.EnsureInitialized(ref _rootFolder, ref _userRootFolderInitialized, ref _userRootFolderSyncLock, () => LibraryManager.GetUserRootFolder(RootFolderPath)); - return _rootFolder; + return _rootFolder ?? (LibraryManager.GetUserRootFolder(RootFolderPath)); } private set { _rootFolder = value; - - if (_rootFolder == null) - { - _userRootFolderInitialized = false; - } } } @@ -153,22 +139,6 @@ namespace MediaBrowser.Controller.Entities } } - /// - /// Gets the last date modified of the configuration - /// - /// The configuration date last modified. - [IgnoreDataMember] - public DateTime ConfigurationDateLastModified - { - get - { - // Ensure it's been lazy loaded - var config = Configuration; - - return FileSystem.GetLastWriteTimeUtc(ConfigurationFilePath); - } - } - /// /// Reloads the root media folder /// @@ -203,13 +173,22 @@ namespace MediaBrowser.Controller.Entities { // Move configuration var newConfigDirectory = GetConfigurationDirectoryPath(newName); + var oldConfigurationDirectory = ConfigurationDirectoryPath; // Exceptions will be thrown if these paths already exist if (Directory.Exists(newConfigDirectory)) { Directory.Delete(newConfigDirectory, true); } - Directory.Move(ConfigurationDirectoryPath, newConfigDirectory); + + if (Directory.Exists(oldConfigurationDirectory)) + { + Directory.Move(oldConfigurationDirectory, newConfigDirectory); + } + else + { + Directory.CreateDirectory(newConfigDirectory); + } var customLibraryPath = GetRootFolderPath(Name); @@ -228,7 +207,6 @@ namespace MediaBrowser.Controller.Entities Name = newName; // Force these to be lazy loaded again - _configurationDirectoryPath = null; RootFolder = null; // Kick off a task to validate the media library @@ -237,26 +215,16 @@ namespace MediaBrowser.Controller.Entities return RefreshMetadata(CancellationToken.None, forceSave: true, forceRefresh: true); } - /// - /// The _configuration directory path - /// - private string _configurationDirectoryPath; /// /// Gets the path to the user's configuration directory /// /// The configuration directory path. + [IgnoreDataMember] private string ConfigurationDirectoryPath { get { - if (_configurationDirectoryPath == null) - { - _configurationDirectoryPath = GetConfigurationDirectoryPath(Name); - - Directory.CreateDirectory(_configurationDirectoryPath); - } - - return _configurationDirectoryPath; + return GetConfigurationDirectoryPath(Name); } } @@ -281,6 +249,7 @@ namespace MediaBrowser.Controller.Entities /// Gets the path to the user's configuration file /// /// The configuration file path. + [IgnoreDataMember] public string ConfigurationFilePath { get @@ -294,7 +263,9 @@ namespace MediaBrowser.Controller.Entities /// public void SaveConfiguration(IXmlSerializer serializer) { - serializer.SerializeToFile(Configuration, ConfigurationFilePath); + var xmlPath = ConfigurationFilePath; + Directory.CreateDirectory(System.IO.Path.GetDirectoryName(xmlPath)); + serializer.SerializeToFile(Configuration, xmlPath); } /// diff --git a/MediaBrowser.Mono.userprefs b/MediaBrowser.Mono.userprefs index 98959b10ad..3ca97e6bdd 100644 --- a/MediaBrowser.Mono.userprefs +++ b/MediaBrowser.Mono.userprefs @@ -2,10 +2,7 @@ - - - - + diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs index a2a4d5bbf4..8e07bc2667 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs @@ -377,7 +377,7 @@ namespace MediaBrowser.Providers.MediaInfo if (!string.IsNullOrEmpty(genres)) { - video.Genres = genres.Split(new[] { ';', '/' }, StringSplitOptions.RemoveEmptyEntries) + video.Genres = genres.Split(new[] { ';', '/', ',' }, StringSplitOptions.RemoveEmptyEntries) .Where(i => !string.IsNullOrWhiteSpace(i)) .Select(i => i.Trim()) .ToList(); diff --git a/MediaBrowser.Server.Mono/app.config b/MediaBrowser.Server.Mono/app.config index 7a240c6dd7..c5abd3a20e 100644 --- a/MediaBrowser.Server.Mono/app.config +++ b/MediaBrowser.Server.Mono/app.config @@ -8,7 +8,6 @@ - - + diff --git a/MediaBrowser.ServerApplication/App.config b/MediaBrowser.ServerApplication/App.config index 217d3d2760..53788e09af 100644 --- a/MediaBrowser.ServerApplication/App.config +++ b/MediaBrowser.ServerApplication/App.config @@ -11,8 +11,7 @@ - - + diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 935067a336..514fbe6c1b 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -590,7 +590,8 @@ namespace MediaBrowser.ServerApplication { return Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly) .Select(LoadAssembly) - .Where(a => a != null); + .Where(a => a != null) + .ToList(); } catch (DirectoryNotFoundException) { diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 50d25de269..e11c8390f1 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -94,9 +94,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -193,9 +190,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -208,9 +202,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -289,9 +280,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -1486,11 +1474,6 @@ PreserveNewest - - - PreserveNewest - - PreserveNewest @@ -1573,11 +1556,6 @@ PreserveNewest - - - PreserveNewest - - PreserveNewest @@ -1586,21 +1564,6 @@ PreserveNewest - - - PreserveNewest - - - - - PreserveNewest - - - - - PreserveNewest - - PreserveNewest @@ -1765,11 +1728,6 @@ PreserveNewest - - - PreserveNewest - - PreserveNewest