mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-04 07:46:32 +01:00
Decouple demotion detection from deletion
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user