diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index f25688bba3..bd823e0c11 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -730,10 +730,8 @@ namespace Emby.Server.Implementations.Library _fileSystem.CreateDirectory(rootFolderPath); - var tmpAFolder = new AggregateFolder(); - ((Folder)ResolvePath(_fileSystem.GetDirectoryInfo(rootFolderPath))).DeepCopy(tmpAFolder); - var rootFolder = GetItemById(GetNewItemId(rootFolderPath, typeof(AggregateFolder))) as AggregateFolder ?? tmpAFolder; - + var rootFolder = GetItemById(GetNewItemId(rootFolderPath, typeof(AggregateFolder))) as AggregateFolder ?? ((Folder)ResolvePath(_fileSystem.GetDirectoryInfo(rootFolderPath))).DeepCopy(); + // In case program data folder was moved if (!string.Equals(rootFolder.Path, rootFolderPath, StringComparison.Ordinal)) { @@ -801,8 +799,7 @@ namespace Emby.Server.Implementations.Library if (tmpItem == null) { - tmpItem = new UserRootFolder(); - ((Folder)ResolvePath(_fileSystem.GetDirectoryInfo(userRootPath))).DeepCopy(tmpItem); + tmpItem = ((Folder)ResolvePath(_fileSystem.GetDirectoryInfo(userRootPath))).DeepCopy(); } // In case program data folder was moved diff --git a/MediaBrowser.Controller/Entities/BaseItemExtensions.cs b/MediaBrowser.Controller/Entities/BaseItemExtensions.cs index 97e56d1fd0..8ab1788b57 100644 --- a/MediaBrowser.Controller/Entities/BaseItemExtensions.cs +++ b/MediaBrowser.Controller/Entities/BaseItemExtensions.cs @@ -68,7 +68,9 @@ namespace MediaBrowser.Controller.Entities /// /// The source object. /// The destination object. - public static void DeepCopy(this T source, TU dest) + public static void DeepCopy(this T source, TU dest) + where T : BaseItem + where TU : BaseItem { var sourceProps = typeof (T).GetProperties().Where(x => x.CanRead).ToList(); var destProps = typeof(TU).GetProperties() @@ -87,6 +89,19 @@ namespace MediaBrowser.Controller.Entities } + /// + /// Copies all properties on newly created object. Skips properties that do not exist. + /// + /// The source object. + public static TU DeepCopy(this T source) + where T : BaseItem + where TU : BaseItem, new() + { + var dest = new TU(); + source.DeepCopy(dest); + return dest; + } + } }