From aea255f91026598c297d11f032cc483b8608616d Mon Sep 17 00:00:00 2001 From: JPVenson Date: Thu, 14 Nov 2024 10:14:41 +0000 Subject: [PATCH] Deterministic tests my *** --- Jellyfin.Api/Controllers/LibraryStructureController.cs | 9 ++++++++- .../Item/BaseItemRepository.cs | 4 ++-- .../Controllers/LibraryStructureControllerTests.cs | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index c3e3b659b2..7838c2f61c 100644 --- a/Jellyfin.Api/Controllers/LibraryStructureController.cs +++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs @@ -88,7 +88,14 @@ public class LibraryStructureController : BaseJellyfinApiController libraryOptions.PathInfos = Array.ConvertAll(paths, i => new MediaPathInfo(i)); } - await _libraryManager.AddVirtualFolder(name, collectionType, libraryOptions, refreshLibrary).ConfigureAwait(false); + try + { + await _libraryManager.AddVirtualFolder(name, collectionType, libraryOptions, refreshLibrary).ConfigureAwait(false); + } + catch (System.Exception ex) + { + return BadRequest(ex.ToString()); + } return NoContent(); } diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs index 14300d237b..f62d6fc1ae 100644 --- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs +++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs @@ -83,7 +83,7 @@ public sealed class BaseItemRepository( context.Peoples.Where(e => e.BaseItems!.Count == 0).ExecuteDelete(); context.Chapters.Where(e => e.ItemId == id).ExecuteDelete(); context.MediaStreamInfos.Where(e => e.ItemId == id).ExecuteDelete(); - context.AncestorIds.Where(e => e.ItemId == id).ExecuteDelete(); + context.AncestorIds.Where(e => e.ItemId == id || e.ParentItemId == id).ExecuteDelete(); context.ItemValuesMap.Where(e => e.ItemId == id).ExecuteDelete(); context.ItemValues.Where(e => e.BaseItemsMap!.Count == 0).ExecuteDelete(); context.BaseItemImageInfos.Where(e => e.ItemId == id).ExecuteDelete(); @@ -1292,7 +1292,7 @@ public sealed class BaseItemRepository( { if (!context.BaseItems.Any(f => f.Id == ancestorId)) { - throw new InvalidOperationException($"Cannot link non-existent parent: {ancestorId}"); + continue; } context.AncestorIds.Add(new AncestorId() diff --git a/tests/Jellyfin.Server.Integration.Tests/Controllers/LibraryStructureControllerTests.cs b/tests/Jellyfin.Server.Integration.Tests/Controllers/LibraryStructureControllerTests.cs index dc8c33c73f..6b749f0a89 100644 --- a/tests/Jellyfin.Server.Integration.Tests/Controllers/LibraryStructureControllerTests.cs +++ b/tests/Jellyfin.Server.Integration.Tests/Controllers/LibraryStructureControllerTests.cs @@ -77,7 +77,7 @@ public sealed class LibraryStructureControllerTests : IClassFixture