aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/Folder.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2026-02-27 21:22:47 +0100
committerShadowghost <Ghost_of_Stone@web.de>2026-02-27 21:22:47 +0100
commit457c53da6f48a1fd3af2b5211c21e3c44b008258 (patch)
tree1821314f146df971b1f9b8d6a9808af0064fe1a3 /MediaBrowser.Controller/Entities/Folder.cs
parent46ffe0af9cc45f84ac91e09991e8b4fde62867ad (diff)
Decouple demotion detection from deletion
Diffstat (limited to 'MediaBrowser.Controller/Entities/Folder.cs')
-rw-r--r--MediaBrowser.Controller/Entities/Folder.cs34
1 files changed, 21 insertions, 13 deletions
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index cc322d0ddd..ed41bdb6ba 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -513,19 +513,6 @@ namespace MediaBrowser.Controller.Entities
// Check if path is in LocalAlternateVersions of any valid child
if (!string.IsNullOrEmpty(item.Path) && alternateVersionPaths.Contains(item.Path))
{
- // If this was a primary (no PrimaryVersionId, no OwnerId), it needs demotion
- if (video.OwnerId.IsEmpty())
- {
- var newPrimary = newItems
- .OfType<Video>()
- .FirstOrDefault(v => (v.LocalAlternateVersions ?? [])
- .Any(p => string.Equals(p, item.Path, StringComparison.OrdinalIgnoreCase)));
- if (newPrimary is not null)
- {
- oldPrimariesToDemote.Add((video, newPrimary));
- }
- }
-
Logger.LogDebug("Item path matches an alternate version, skipping deletion: {Path}", item.Path);
continue;
}
@@ -540,6 +527,27 @@ namespace MediaBrowser.Controller.Entities
LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }, this, false);
}
}
+
+ // Detect items that need demotion AFTER all deletions have run.
+ // DeleteItem may promote an alternate to primary (clearing its OwnerId),
+ // so we must check OwnerId after the deletion loop to see the updated state.
+ foreach (var item in itemsRemoved.Except(actuallyRemoved))
+ {
+ if (item is Video video
+ && video.OwnerId.IsEmpty()
+ && !string.IsNullOrEmpty(item.Path)
+ && alternateVersionPaths.Contains(item.Path))
+ {
+ var newPrimary = newItems
+ .OfType<Video>()
+ .FirstOrDefault(v => (v.LocalAlternateVersions ?? [])
+ .Any(p => string.Equals(p, item.Path, StringComparison.OrdinalIgnoreCase)));
+ if (newPrimary is not null)
+ {
+ oldPrimariesToDemote.Add((video, newPrimary));
+ }
+ }
+ }
}
if (newItems.Count > 0)