diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-03-14 20:26:20 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-03-14 20:26:40 +0100 |
| commit | ebc15d3e279d52a55f49e4de5aca2153f64ac636 (patch) | |
| tree | eaba40fff394e3343c64bcd43119b0c8206cf40b /Emby.Server.Implementations | |
| parent | 4b48cad6f79123c25bb3c15c006afd27f0b49e45 (diff) | |
Handle removed alternates
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/Library/LibraryManager.cs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 11a6f58800..57db845cb2 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -432,13 +432,43 @@ namespace Emby.Server.Implementations.Library if (item is Video video && !video.PrimaryVersionId.HasValue && video.OwnerId.IsEmpty()) { var localAlternateIds = GetLocalAlternateVersionIds(video).ToHashSet(); - var alternateVersions = localAlternateIds + var allAlternateVersions = localAlternateIds .Concat(GetLinkedAlternateVersions(video).Select(v => v.Id)) .Distinct() .Select(id => GetItemById(id)) .OfType<Video>() .ToList(); + // Partition alternates by whether their files still exist on disk + var alternateVersions = new List<Video>(); + var missingAlternates = new List<Video>(); + foreach (var alt in allAlternateVersions) + { + if (!string.IsNullOrEmpty(alt.Path) && !_fileSystem.FileExists(alt.Path)) + { + missingAlternates.Add(alt); + } + else + { + alternateVersions.Add(alt); + } + } + + // Delete alternates whose files no longer exist to avoid ghost items. + // Clear PrimaryVersionId first so DeleteItem doesn't try to update the primary being deleted. + foreach (var missing in missingAlternates) + { + _logger.LogInformation( + "Deleting missing alternate version {Name} ({Path})", + missing.Name ?? "Unknown name", + missing.Path ?? string.Empty); + missing.SetPrimaryVersionId(null); + missing.OwnerId = Guid.Empty; + missing.LocalAlternateVersions = []; + missing.LinkedAlternateVersions = []; + DeleteItem(missing, new DeleteOptions { DeleteFileLocation = false }, false); + } + if (alternateVersions.Count > 0) { _logger.LogInformation( |
