From 04d1a53d199bbf5fced102daae77b3ef0d64474d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 29 Dec 2013 12:07:29 -0500 Subject: don't persist lazy loaded paths --- MediaBrowser.Controller/Entities/User.cs | 63 +++++++++----------------------- 1 file changed, 17 insertions(+), 46 deletions(-) (limited to 'MediaBrowser.Controller/Entities') diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index 0a935cd0d..466e709dd 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); } /// -- cgit v1.2.3