diff --git a/ErsatzTV.Application/ConcurrencyExtensions.cs b/ErsatzTV.Application/ConcurrencyExtensions.cs
new file mode 100644
index 000000000..f77965b5c
--- /dev/null
+++ b/ErsatzTV.Application/ConcurrencyExtensions.cs
@@ -0,0 +1,33 @@
+using ErsatzTV.Core;
+using ErsatzTV.Core.Errors;
+using Microsoft.EntityFrameworkCore;
+
+namespace ErsatzTV.Application;
+
+public static class ConcurrencyExtensions
+{
+ ///
+ /// Persist pending changes, mapping the EF optimistic-concurrency failure to
+ /// (→ 412). When a versioned root carries an
+ /// IsConcurrencyToken column and its Version is bumped before saving, EF emits
+ /// UPDATE … WHERE Id=@id AND Version=@original; a zero-row result (another writer won
+ /// the race between our load and save) throws .
+ /// This is the backstop that closes the load→save TOCTOU the handler pre-check cannot.
+ /// Issue #253.
+ ///
+ public static async Task> SaveChangesWithConcurrencyGuard(
+ this DbContext dbContext,
+ CancellationToken cancellationToken)
+ {
+ try
+ {
+ await dbContext.SaveChangesAsync(cancellationToken);
+ return Unit.Default;
+ }
+ catch (DbUpdateConcurrencyException)
+ {
+ return new PreconditionFailedError(
+ "The resource was modified by another request. Reload and try again.");
+ }
+ }
+}
diff --git a/ErsatzTV.Application/Emby/Commands/DisconnectEmbyHandler.cs b/ErsatzTV.Application/Emby/Commands/DisconnectEmbyHandler.cs
index 9f75026c6..0fc4a26b4 100644
--- a/ErsatzTV.Application/Emby/Commands/DisconnectEmbyHandler.cs
+++ b/ErsatzTV.Application/Emby/Commands/DisconnectEmbyHandler.cs
@@ -30,12 +30,21 @@ public class DisconnectEmbyHandler : IRequestHandler ids = await _mediaSourceRepository.DeleteAllEmby();
- await _searchIndex.RemoveItems(ids);
- _searchIndex.Commit();
- await _embySecretStore.DeleteAll();
- _entityLocker.UnlockRemoteMediaSource();
+ // This is a terminal handler with no lock handoff (unlike the Plex pin-flow handlers) —
+ // release unconditionally so a throw from any awaited dependency (repo delete, search-index
+ // commit, secret store) can't wedge the Emby lock until restart (design #202 finding 7).
+ try
+ {
+ List ids = await _mediaSourceRepository.DeleteAllEmby();
+ await _searchIndex.RemoveItems(ids);
+ _searchIndex.Commit();
+ await _embySecretStore.DeleteAll();
- return Unit.Default;
+ return Unit.Default;
+ }
+ finally
+ {
+ _entityLocker.UnlockRemoteMediaSource();
+ }
}
}
diff --git a/ErsatzTV.Application/Emby/Commands/UpdateEmbyPathReplacementsHandler.cs b/ErsatzTV.Application/Emby/Commands/UpdateEmbyPathReplacementsHandler.cs
index 66661fbed..33c3964c5 100644
--- a/ErsatzTV.Application/Emby/Commands/UpdateEmbyPathReplacementsHandler.cs
+++ b/ErsatzTV.Application/Emby/Commands/UpdateEmbyPathReplacementsHandler.cs
@@ -1,4 +1,4 @@
-using ErsatzTV.Core;
+using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
@@ -12,12 +12,29 @@ public class UpdateEmbyPathReplacementsHandler : IRequestHandler
_mediaSourceRepository = mediaSourceRepository;
- public Task> Handle(
+ public async Task> Handle(
UpdateEmbyPathReplacements request,
- CancellationToken cancellationToken) =>
- Validate(request, cancellationToken)
- .MapT(pms => MergePathReplacements(request, pms))
- .Bind(v => v.ToEitherAsync());
+ CancellationToken cancellationToken)
+ {
+ Option maybeSource =
+ await _mediaSourceRepository.GetEmby(request.EmbyMediaSourceId, cancellationToken);
+
+ return await maybeSource.Match(
+ Some: async embyMediaSource =>
+ {
+ Option maybeError = ValidateItems(request, embyMediaSource);
+ return await maybeError.Match(
+ Some: error => Task.FromResult(Left(error)),
+ None: async () =>
+ {
+ await MergePathReplacements(request, embyMediaSource);
+ return Right(Unit.Default);
+ });
+ },
+ None: () => Task.FromResult(
+ Left(
+ BaseError.New($"Emby media source {request.EmbyMediaSourceId} does not exist."))));
+ }
private Task MergePathReplacements(
UpdateEmbyPathReplacements request,
@@ -37,12 +54,38 @@ public class UpdateEmbyPathReplacementsHandler : IRequestHandler
new() { Id = vm.Id, EmbyPath = vm.EmbyPath, LocalPath = vm.LocalPath };
- private Task> Validate(UpdateEmbyPathReplacements request, CancellationToken cancellationToken) =>
- EmbyMediaSourceMustExist(request, cancellationToken);
+ // Defense-in-depth for design #202 findings 2c/8 — the repo UPDATE is scoped by
+ // EmbyMediaSourceId, but reject a foreign/blank/null row here too, before any write, so the
+ // mutation is all-or-nothing.
+ private static Option ValidateItems(
+ UpdateEmbyPathReplacements request,
+ EmbyMediaSource embyMediaSource)
+ {
+ List items = request.PathReplacements ?? [];
- private Task> EmbyMediaSourceMustExist(
- UpdateEmbyPathReplacements request, CancellationToken cancellationToken) =>
- _mediaSourceRepository.GetEmby(request.EmbyMediaSourceId, cancellationToken)
- .Map(v => v.ToValidation(
- $"Emby media source {request.EmbyMediaSourceId} does not exist."));
+ if (items.Any(item => item is null))
+ {
+ return BaseError.New("Path replacement items must not be null.");
+ }
+
+ if (items.Any(item => string.IsNullOrWhiteSpace(item.EmbyPath) || string.IsNullOrWhiteSpace(item.LocalPath)))
+ {
+ return BaseError.New("Each path replacement requires a non-blank Emby path and local path.");
+ }
+
+ var existingIds = (embyMediaSource.PathReplacements ?? new List())
+ .Map(pr => pr.Id)
+ .ToList();
+ var foreignIds = items.Filter(item => item.Id > 0 && !existingIds.Contains(item.Id))
+ .Map(item => item.Id)
+ .ToList();
+ if (foreignIds.Count > 0)
+ {
+ return BaseError.New(
+ $"Path replacement id(s) {string.Join(", ", foreignIds)} do not belong to Emby media source " +
+ $"{request.EmbyMediaSourceId}.");
+ }
+
+ return Option.None;
+ }
}
diff --git a/ErsatzTV.Application/Jellyfin/Commands/DisconnectJellyfinHandler.cs b/ErsatzTV.Application/Jellyfin/Commands/DisconnectJellyfinHandler.cs
index babacadcc..b533cc3f7 100644
--- a/ErsatzTV.Application/Jellyfin/Commands/DisconnectJellyfinHandler.cs
+++ b/ErsatzTV.Application/Jellyfin/Commands/DisconnectJellyfinHandler.cs
@@ -30,12 +30,21 @@ public class DisconnectJellyfinHandler : IRequestHandler ids = await _mediaSourceRepository.DeleteAllJellyfin();
- await _searchIndex.RemoveItems(ids);
- _searchIndex.Commit();
- await _jellyfinSecretStore.DeleteAll();
- _entityLocker.UnlockRemoteMediaSource();
+ // This is a terminal handler with no lock handoff (unlike the Plex pin-flow handlers) —
+ // release unconditionally so a throw from any awaited dependency (repo delete, search-index
+ // commit, secret store) can't wedge the Jellyfin lock until restart (design #202 finding 7).
+ try
+ {
+ List ids = await _mediaSourceRepository.DeleteAllJellyfin();
+ await _searchIndex.RemoveItems(ids);
+ _searchIndex.Commit();
+ await _jellyfinSecretStore.DeleteAll();
- return Unit.Default;
+ return Unit.Default;
+ }
+ finally
+ {
+ _entityLocker.UnlockRemoteMediaSource();
+ }
}
}
diff --git a/ErsatzTV.Application/Jellyfin/Commands/UpdateJellyfinPathReplacementsHandler.cs b/ErsatzTV.Application/Jellyfin/Commands/UpdateJellyfinPathReplacementsHandler.cs
index 9ac74f1eb..c74408f09 100644
--- a/ErsatzTV.Application/Jellyfin/Commands/UpdateJellyfinPathReplacementsHandler.cs
+++ b/ErsatzTV.Application/Jellyfin/Commands/UpdateJellyfinPathReplacementsHandler.cs
@@ -1,4 +1,4 @@
-using ErsatzTV.Core;
+using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
@@ -12,12 +12,29 @@ public class UpdateJellyfinPathReplacementsHandler : IRequestHandler
_mediaSourceRepository = mediaSourceRepository;
- public Task> Handle(
+ public async Task> Handle(
UpdateJellyfinPathReplacements request,
- CancellationToken cancellationToken) =>
- Validate(request)
- .MapT(pms => MergePathReplacements(request, pms))
- .Bind(v => v.ToEitherAsync());
+ CancellationToken cancellationToken)
+ {
+ Option maybeSource =
+ await _mediaSourceRepository.GetJellyfin(request.JellyfinMediaSourceId);
+
+ return await maybeSource.Match(
+ Some: async jellyfinMediaSource =>
+ {
+ Option maybeError = ValidateItems(request, jellyfinMediaSource);
+ return await maybeError.Match(
+ Some: error => Task.FromResult(Left(error)),
+ None: async () =>
+ {
+ await MergePathReplacements(request, jellyfinMediaSource);
+ return Right(Unit.Default);
+ });
+ },
+ None: () => Task.FromResult(
+ Left(
+ BaseError.New($"Jellyfin media source {request.JellyfinMediaSourceId} does not exist."))));
+ }
private Task MergePathReplacements(
UpdateJellyfinPathReplacements request,
@@ -37,12 +54,38 @@ public class UpdateJellyfinPathReplacementsHandler : IRequestHandler
new() { Id = vm.Id, JellyfinPath = vm.JellyfinPath, LocalPath = vm.LocalPath };
- private Task> Validate(UpdateJellyfinPathReplacements request) =>
- JellyfinMediaSourceMustExist(request);
+ // Defense-in-depth for design #202 findings 2c/8 — the repo UPDATE is scoped by
+ // JellyfinMediaSourceId, but reject a foreign/blank/null row here too, before any write, so the
+ // mutation is all-or-nothing.
+ private static Option ValidateItems(
+ UpdateJellyfinPathReplacements request,
+ JellyfinMediaSource jellyfinMediaSource)
+ {
+ List items = request.PathReplacements ?? [];
- private Task> JellyfinMediaSourceMustExist(
- UpdateJellyfinPathReplacements request) =>
- _mediaSourceRepository.GetJellyfin(request.JellyfinMediaSourceId)
- .Map(v => v.ToValidation(
- $"Jellyfin media source {request.JellyfinMediaSourceId} does not exist."));
+ if (items.Any(item => item is null))
+ {
+ return BaseError.New("Path replacement items must not be null.");
+ }
+
+ if (items.Any(item => string.IsNullOrWhiteSpace(item.JellyfinPath) || string.IsNullOrWhiteSpace(item.LocalPath)))
+ {
+ return BaseError.New("Each path replacement requires a non-blank Jellyfin path and local path.");
+ }
+
+ var existingIds = (jellyfinMediaSource.PathReplacements ?? new List())
+ .Map(pr => pr.Id)
+ .ToList();
+ var foreignIds = items.Filter(item => item.Id > 0 && !existingIds.Contains(item.Id))
+ .Map(item => item.Id)
+ .ToList();
+ if (foreignIds.Count > 0)
+ {
+ return BaseError.New(
+ $"Path replacement id(s) {string.Join(", ", foreignIds)} do not belong to Jellyfin media source " +
+ $"{request.JellyfinMediaSourceId}.");
+ }
+
+ return Option.None;
+ }
}
diff --git a/ErsatzTV.Application/Libraries/Commands/CreateLocalLibraryHandler.cs b/ErsatzTV.Application/Libraries/Commands/CreateLocalLibraryHandler.cs
index 7dc41a2c1..0f5976a34 100644
--- a/ErsatzTV.Application/Libraries/Commands/CreateLocalLibraryHandler.cs
+++ b/ErsatzTV.Application/Libraries/Commands/CreateLocalLibraryHandler.cs
@@ -1,4 +1,5 @@
-using System.Threading.Channels;
+using System.IO.Abstractions;
+using System.Threading.Channels;
using ErsatzTV.Application.MediaSources;
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
@@ -14,15 +15,18 @@ public class CreateLocalLibraryHandler : LocalLibraryHandlerBase,
{
private readonly IDbContextFactory _dbContextFactory;
private readonly IEntityLocker _entityLocker;
+ private readonly IFileSystem _fileSystem;
private readonly ChannelWriter _scannerWorkerChannel;
public CreateLocalLibraryHandler(
ChannelWriter scannerWorkerChannel,
IEntityLocker entityLocker,
+ IFileSystem fileSystem,
IDbContextFactory dbContextFactory)
{
_scannerWorkerChannel = scannerWorkerChannel;
_entityLocker = entityLocker;
+ _fileSystem = fileSystem;
_dbContextFactory = dbContextFactory;
}
@@ -31,7 +35,7 @@ public class CreateLocalLibraryHandler : LocalLibraryHandlerBase,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
- Validation validation = await Validate(dbContext, request);
+ Validation validation = await Validate(_fileSystem, dbContext, request);
return await validation.Apply(localLibrary => PersistLocalLibrary(dbContext, localLibrary));
}
@@ -61,11 +65,13 @@ public class CreateLocalLibraryHandler : LocalLibraryHandlerBase,
}
private static Task> Validate(
+ IFileSystem fileSystem,
TvContext dbContext,
CreateLocalLibrary request) =>
MediaSourceMustExist(dbContext, request)
.BindT(localLibrary => NameMustBeValid(request, localLibrary))
- .BindT(localLibrary => PathsMustBeValid(dbContext, localLibrary));
+ .BindT(localLibrary => PathsMustBeValid(dbContext, localLibrary))
+ .BindT(localLibrary => NewPathsMustExist(fileSystem, localLibrary));
private static Task> MediaSourceMustExist(
TvContext dbContext,
diff --git a/ErsatzTV.Application/Libraries/Commands/LocalLibraryHandlerBase.cs b/ErsatzTV.Application/Libraries/Commands/LocalLibraryHandlerBase.cs
index 795d430fd..2fef7469f 100644
--- a/ErsatzTV.Application/Libraries/Commands/LocalLibraryHandlerBase.cs
+++ b/ErsatzTV.Application/Libraries/Commands/LocalLibraryHandlerBase.cs
@@ -1,4 +1,5 @@
-using ErsatzTV.Core;
+using System.IO.Abstractions;
+using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -14,6 +15,28 @@ public abstract class LocalLibraryHandlerBase
.Bind(_ => request.NotLongerThan(50)(c => c.Name))
.Map(_ => localLibrary).AsTask();
+ ///
+ /// Validates that every NEW path (Id < 1 — see design #202 §C2) exists on the
+ /// filesystem. Existing rows are exempt: an unmounted share must not block saving a rename,
+ /// matching Blazor's behavior of only checking existence when a path is added.
+ ///
+ protected static Task> NewPathsMustExist(
+ IFileSystem fileSystem,
+ LocalLibrary localLibrary)
+ {
+ List missing = localLibrary.Paths
+ .Filter(p => p.Id < 1)
+ .Filter(p => !fileSystem.Directory.Exists(p.Path))
+ .Map(p => p.Path)
+ .ToList();
+
+ Validation result = missing.Count == 0
+ ? Success(localLibrary)
+ : Fail($"Path(s) do not exist on the filesystem: {string.Join(", ", missing)}");
+
+ return result.AsTask();
+ }
+
protected static async Task> PathsMustBeValid(
TvContext dbContext,
LocalLibrary localLibrary,
diff --git a/ErsatzTV.Application/Libraries/Commands/MoveLocalLibraryPathHandler.cs b/ErsatzTV.Application/Libraries/Commands/MoveLocalLibraryPathHandler.cs
index 0a85786d7..b9f05843c 100644
--- a/ErsatzTV.Application/Libraries/Commands/MoveLocalLibraryPathHandler.cs
+++ b/ErsatzTV.Application/Libraries/Commands/MoveLocalLibraryPathHandler.cs
@@ -79,10 +79,31 @@ public class MoveLocalLibraryPathHandler : IRequestHandler> Validate(
TvContext dbContext,
MoveLocalLibraryPath request,
- CancellationToken cancellationToken) =>
- (await LibraryPathMustExist(dbContext, request, cancellationToken),
- await LocalLibraryMustExist(dbContext, request, cancellationToken))
- .Apply((libraryPath, localLibrary) => new Parameters(libraryPath, localLibrary));
+ CancellationToken cancellationToken)
+ {
+ Validation parameters =
+ (await LibraryPathMustExist(dbContext, request, cancellationToken),
+ await LocalLibraryMustExist(dbContext, request, cancellationToken))
+ .Apply((libraryPath, localLibrary) => new Parameters(libraryPath, localLibrary));
+
+ return parameters
+ .Bind(TargetLibraryMustDiffer)
+ .Bind(TargetLibraryMustMatchMediaKind);
+ }
+
+ // Blazor's move dialog filters the target-library picker to same-kind, source-excluded
+ // libraries only (MoveLocalLibraryPathDialog.razor:82); an API/MCP client bypasses that
+ // client-side filter today, so #202 moves both invariants into the handler (design #202 §C5,
+ // finding 3).
+ private static Validation TargetLibraryMustDiffer(Parameters parameters) =>
+ parameters.LibraryPath.LibraryId == parameters.Library.Id
+ ? Fail("Target library must be different from the source path's current library")
+ : Success(parameters);
+
+ private static Validation TargetLibraryMustMatchMediaKind(Parameters parameters) =>
+ parameters.LibraryPath.Library.MediaKind != parameters.Library.MediaKind
+ ? Fail("Target library must have the same media kind as the source path's library")
+ : Success(parameters);
private static Task> LibraryPathMustExist(
TvContext dbContext,
diff --git a/ErsatzTV.Application/Libraries/Commands/UpdateLocalLibraryHandler.cs b/ErsatzTV.Application/Libraries/Commands/UpdateLocalLibraryHandler.cs
index b20728c12..8e4cac975 100644
--- a/ErsatzTV.Application/Libraries/Commands/UpdateLocalLibraryHandler.cs
+++ b/ErsatzTV.Application/Libraries/Commands/UpdateLocalLibraryHandler.cs
@@ -1,4 +1,5 @@
-using System.Threading.Channels;
+using System.IO.Abstractions;
+using System.Threading.Channels;
using Dapper;
using ErsatzTV.Application.MediaSources;
using ErsatzTV.Core;
@@ -17,17 +18,20 @@ public class UpdateLocalLibraryHandler : LocalLibraryHandlerBase,
{
private readonly IDbContextFactory _dbContextFactory;
private readonly IEntityLocker _entityLocker;
+ private readonly IFileSystem _fileSystem;
private readonly ChannelWriter _scannerWorkerChannel;
private readonly ISearchIndex _searchIndex;
public UpdateLocalLibraryHandler(
ChannelWriter scannerWorkerChannel,
IEntityLocker entityLocker,
+ IFileSystem fileSystem,
ISearchIndex searchIndex,
IDbContextFactory dbContextFactory)
{
_scannerWorkerChannel = scannerWorkerChannel;
_entityLocker = entityLocker;
+ _fileSystem = fileSystem;
_searchIndex = searchIndex;
_dbContextFactory = dbContextFactory;
}
@@ -37,7 +41,8 @@ public class UpdateLocalLibraryHandler : LocalLibraryHandlerBase,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
- Validation validation = await Validate(dbContext, request, cancellationToken);
+ Validation validation =
+ await Validate(_fileSystem, dbContext, request, cancellationToken);
return await validation.Apply(parameters => UpdateLocalLibrary(dbContext, parameters));
}
@@ -114,13 +119,15 @@ public class UpdateLocalLibraryHandler : LocalLibraryHandlerBase,
}
private static Task> Validate(
+ IFileSystem fileSystem,
TvContext dbContext,
UpdateLocalLibrary request,
CancellationToken cancellationToken) =>
LocalLibraryMustExist(dbContext, request, cancellationToken)
.BindT(parameters => NameMustBeValid(request, parameters.Incoming).MapT(_ => parameters))
.BindT(parameters => PathsMustBeValid(dbContext, parameters.Incoming, parameters.Existing.Id)
- .MapT(_ => parameters));
+ .MapT(_ => parameters))
+ .BindT(parameters => NewPathsMustExist(fileSystem, parameters.Incoming).MapT(_ => parameters));
private static Task> LocalLibraryMustExist(
TvContext dbContext,
diff --git a/ErsatzTV.Application/Plex/Commands/SignOutOfPlexHandler.cs b/ErsatzTV.Application/Plex/Commands/SignOutOfPlexHandler.cs
index c20d4231c..4d1986bfb 100644
--- a/ErsatzTV.Application/Plex/Commands/SignOutOfPlexHandler.cs
+++ b/ErsatzTV.Application/Plex/Commands/SignOutOfPlexHandler.cs
@@ -27,12 +27,22 @@ public class SignOutOfPlexHandler : IRequestHandler> Handle(SignOutOfPlex request, CancellationToken cancellationToken)
{
- List ids = await _mediaSourceRepository.DeleteAllPlex();
- await _searchIndex.RemoveItems(ids);
- _searchIndex.Commit();
- await _plexSecretStore.DeleteAll();
- _entityLocker.UnlockPlex();
+ // Terminal handler (no lock handoff): release the Plex lock on EVERY exit via finally so a throw
+ // from any awaited dependency (repo delete, search-index commit, secret store) cannot wedge Plex
+ // locked at 409 until restart (#202 §C6 / finding 7). This is the UNCONDITIONAL-finally case —
+ // contrast the pin-flow handlers, which hand the lock off and must NOT use a blanket finally.
+ try
+ {
+ List ids = await _mediaSourceRepository.DeleteAllPlex();
+ await _searchIndex.RemoveItems(ids);
+ _searchIndex.Commit();
+ await _plexSecretStore.DeleteAll();
- return Unit.Default;
+ return Unit.Default;
+ }
+ finally
+ {
+ _entityLocker.UnlockPlex();
+ }
}
}
diff --git a/ErsatzTV.Application/Plex/Commands/TryCompletePlexPinFlowHandler.cs b/ErsatzTV.Application/Plex/Commands/TryCompletePlexPinFlowHandler.cs
index bc4fbfd48..2a8e0c5a4 100644
--- a/ErsatzTV.Application/Plex/Commands/TryCompletePlexPinFlowHandler.cs
+++ b/ErsatzTV.Application/Plex/Commands/TryCompletePlexPinFlowHandler.cs
@@ -1,5 +1,6 @@
-using System.Threading.Channels;
+using System.Threading.Channels;
using ErsatzTV.Core;
+using ErsatzTV.Core.Interfaces.Locking;
using ErsatzTV.Core.Interfaces.Plex;
namespace ErsatzTV.Application.Plex;
@@ -7,34 +8,59 @@ namespace ErsatzTV.Application.Plex;
public class TryCompletePlexPinFlowHandler : IRequestHandler>
{
private readonly ChannelWriter _channel;
+ private readonly IEntityLocker _entityLocker;
private readonly IPlexTvApiClient _plexTvApiClient;
public TryCompletePlexPinFlowHandler(
IPlexTvApiClient plexTvApiClient,
- ChannelWriter channel)
+ ChannelWriter channel,
+ IEntityLocker entityLocker)
{
_plexTvApiClient = plexTvApiClient;
_channel = channel;
+ _entityLocker = entityLocker;
}
public async Task>
Handle(TryCompletePlexPinFlow request, CancellationToken cancellationToken)
{
+ // Lock-release discipline (#202 §C1.6 / §C6): the Plex lock this pin flow holds is released
+ // ONLY on non-handoff exits — the 2-minute timeout (Task.Delay throws
+ // OperationCanceledException), a poll exception, a failed enqueue, or the (effectively dead)
+ // return-false at loop entry. On SUCCESS the lock is HANDED OFF to SynchronizePlexMediaSources,
+ // whose handler is the sole releaser after server discovery (SynchronizePlexMediaSourcesHandler).
+ // This is deliberately NOT an unconditional finally: a blanket release here would double-release
+ // AND release before discovery, re-opening the finding-5 race (an empty server list reading as
+ // success). Contrast the terminal SignOutOfPlexHandler, which DOES use finally (it has no handoff).
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2));
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, cancellationToken);
CancellationToken token = linkedTokenSource.Token;
- while (!token.IsCancellationRequested)
+ try
{
- bool result = await _plexTvApiClient.TryCompletePinFlow(request.AuthPin);
- if (result)
+ while (!token.IsCancellationRequested)
{
- await _channel.WriteAsync(new SynchronizePlexMediaSources(), token);
- return true;
+ bool result = await _plexTvApiClient.TryCompletePinFlow(request.AuthPin);
+ if (result)
+ {
+ // hand the lock off to the sync handler — do NOT release on this success path
+ await _channel.WriteAsync(new SynchronizePlexMediaSources(), token);
+ return true;
+ }
+
+ await Task.Delay(TimeSpan.FromSeconds(1), token);
}
- await Task.Delay(TimeSpan.FromSeconds(1), token);
+ // effectively unreachable (Task.Delay throws on cancellation before the loop condition is
+ // re-evaluated) but if the flow ever ends here it abandoned without auth → release
+ _entityLocker.UnlockPlex();
+ return false;
+ }
+ catch (Exception)
+ {
+ // non-handoff exit: timeout-throw, poll exception, or failed enqueue — release the lock so an
+ // abandoned flow does not wedge Plex locked, then rethrow (PlexService logs it as before)
+ _entityLocker.UnlockPlex();
+ throw;
}
-
- return false;
}
}
diff --git a/ErsatzTV.Application/Plex/Commands/UpdatePlexPathReplacementsHandler.cs b/ErsatzTV.Application/Plex/Commands/UpdatePlexPathReplacementsHandler.cs
index 6192f90dd..70a8b02c0 100644
--- a/ErsatzTV.Application/Plex/Commands/UpdatePlexPathReplacementsHandler.cs
+++ b/ErsatzTV.Application/Plex/Commands/UpdatePlexPathReplacementsHandler.cs
@@ -35,14 +35,56 @@ public class
private static PlexPathReplacement Project(PlexPathReplacementItem vm) =>
new() { Id = vm.Id, PlexPath = vm.PlexPath, LocalPath = vm.LocalPath };
- private Task> Validate(
+ private async Task> Validate(
UpdatePlexPathReplacements request,
- CancellationToken cancellationToken) =>
- PlexMediaSourceMustExist(request, cancellationToken);
+ CancellationToken cancellationToken)
+ {
+ Option maybeSource =
+ await _mediaSourceRepository.GetPlex(request.PlexMediaSourceId, cancellationToken);
- private Task> PlexMediaSourceMustExist(
+ foreach (PlexMediaSource plexMediaSource in maybeSource)
+ {
+ return ValidatePathReplacements(request, plexMediaSource);
+ }
+
+ return Fail(
+ BaseError.New($"Plex media source {request.PlexMediaSourceId} does not exist."));
+ }
+
+ // Programmatic clients now reach this handler directly (#202), so validate what the Blazor form
+ // enforced plus the cross-source ownership hole (finding 2c/8): reject a null list, null items,
+ // blank RemotePath/LocalPath, and any positive Id NOT owned by this source — all before any write,
+ // so there is no partial mutation.
+ private static Validation ValidatePathReplacements(
UpdatePlexPathReplacements request,
- CancellationToken cancellationToken) =>
- _mediaSourceRepository.GetPlex(request.PlexMediaSourceId, cancellationToken)
- .Map(v => v.ToValidation($"Plex media source {request.PlexMediaSourceId} does not exist."));
+ PlexMediaSource plexMediaSource)
+ {
+ List items = request.PathReplacements;
+ if (items is null)
+ {
+ return Fail(BaseError.New("[PathReplacements] is required"));
+ }
+
+ if (items.Any(i => i is null))
+ {
+ return Fail(BaseError.New("[PathReplacements] must not contain null items"));
+ }
+
+ if (items.Any(i => string.IsNullOrWhiteSpace(i.PlexPath) || string.IsNullOrWhiteSpace(i.LocalPath)))
+ {
+ return Fail(
+ BaseError.New("Each path replacement requires a non-empty RemotePath and LocalPath"));
+ }
+
+ var ownedIds = Optional(plexMediaSource.PathReplacements).Flatten().Map(pr => pr.Id).ToHashSet();
+ List foreignIds = items.Filter(i => i.Id > 0 && !ownedIds.Contains(i.Id)).Map(i => i.Id).ToList();
+ if (foreignIds.Count > 0)
+ {
+ return Fail(
+ BaseError.New(
+ $"Path replacement {foreignIds[0]} does not belong to Plex media source {request.PlexMediaSourceId}"));
+ }
+
+ return Success(plexMediaSource);
+ }
}
diff --git a/ErsatzTV.Application/Scheduling/BlockViewModel.cs b/ErsatzTV.Application/Scheduling/BlockViewModel.cs
index d54a36213..cda0dbe9d 100644
--- a/ErsatzTV.Application/Scheduling/BlockViewModel.cs
+++ b/ErsatzTV.Application/Scheduling/BlockViewModel.cs
@@ -8,4 +8,5 @@ public record BlockViewModel(
string GroupName,
string Name,
int Minutes,
- BlockStopScheduling StopScheduling);
+ BlockStopScheduling StopScheduling,
+ int Version);
diff --git a/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItems.cs b/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItems.cs
index 1aebb0633..7f7173da1 100644
--- a/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItems.cs
+++ b/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItems.cs
@@ -9,5 +9,6 @@ public record ReplaceBlockItems(
string Name,
int Minutes,
BlockStopScheduling StopScheduling,
- List Items)
+ List Items,
+ Option ExpectedVersion = default)
: IRequest>;
diff --git a/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs b/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs
index a07d5261d..d028e3556 100644
--- a/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs
+++ b/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs
@@ -16,10 +16,21 @@ public class ReplaceBlockItemsHandler(IDbContextFactory dbContextFact
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Validation validation = await Validate(dbContext, request, cancellationToken);
- return await validation.Apply(ps => Persist(dbContext, request, ps, cancellationToken));
+
+ // Introduce the optimistic-concurrency check as a standalone Either AFTER the validation
+ // pipeline (never via Apply) so a PreconditionFailedError survives to a 412 and is not
+ // flattened to a generic 422 by Join() (issue #253 / api-conventions §7a).
+ // LanguageExtensions.ToEither joins the Seq to a single BaseError (the native
+ // Validation.ToEither() would keep Seq and is called explicitly here to avoid that shadow).
+ Either validated = LanguageExtensions.ToEither(validation)
+ .Bind(block => block.CheckVersion(request.ExpectedVersion));
+
+ return await validated.Match(
+ Right: block => Persist(dbContext, request, block, cancellationToken),
+ Left: error => Task.FromResult>(error));
}
- private static async Task Persist(
+ private static async Task> Persist(
TvContext dbContext,
ReplaceBlockItems request,
Block block,
@@ -33,7 +44,10 @@ public class ReplaceBlockItemsHandler(IDbContextFactory dbContextFact
dbContext.RemoveRange(block.Items);
block.Items = request.Items.Map(i => BuildItem(block, i.Index, i)).ToList();
- await dbContext.SaveChangesAsync(cancellationToken);
+ // Unconditional bump: EF emits the root UPDATE only when a scalar actually differs, so a
+ // same-value/no-op save would otherwise write no root row and neither fire the concurrency
+ // token nor rotate other clients' ETags. Bumping guarantees both on every save (issue #253).
+ block.Version++;
// TODO: refresh any playouts that use this schedule
// foreach (Playout playout in programSchedule.Playouts)
@@ -41,7 +55,9 @@ public class ReplaceBlockItemsHandler(IDbContextFactory dbContextFact
// await _channel.WriteAsync(new BuildPlayout(playout.Id, PlayoutBuildMode.Refresh));
// }
- return Unit.Default;
+ // Save through the guard so an EF concurrency failure (a racing writer won between our load
+ // and save) maps to 412 rather than surfacing as a 500.
+ return await dbContext.SaveChangesWithConcurrencyGuard(cancellationToken);
}
private static BlockItem BuildItem(Block block, int index, ReplaceBlockItem item)
diff --git a/ErsatzTV.Application/Scheduling/Mapper.cs b/ErsatzTV.Application/Scheduling/Mapper.cs
index 861d3266f..d82d9325f 100644
--- a/ErsatzTV.Application/Scheduling/Mapper.cs
+++ b/ErsatzTV.Application/Scheduling/Mapper.cs
@@ -32,7 +32,7 @@ internal static class Mapper
new(blockGroup.Id, blockGroup.Name);
internal static BlockViewModel ProjectToViewModel(Block block) =>
- new(block.Id, block.BlockGroupId, block.BlockGroup.Name, block.Name, block.Minutes, block.StopScheduling);
+ new(block.Id, block.BlockGroupId, block.BlockGroup.Name, block.Name, block.Minutes, block.StopScheduling, block.Version);
internal static BlockItemViewModel ProjectToViewModel(BlockItem blockItem) =>
new(
diff --git a/ErsatzTV.Core/Api/MediaSources/LocalLibraryDetailResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/LocalLibraryDetailResponseModel.cs
new file mode 100644
index 000000000..2f824207a
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/LocalLibraryDetailResponseModel.cs
@@ -0,0 +1,11 @@
+using ErsatzTV.Core.Domain;
+
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record LocalLibraryDetailResponseModel(
+ int Id,
+ string Name,
+ LibraryMediaKind MediaKind,
+ bool IsLocked,
+ int MediaItemCount,
+ List Paths);
diff --git a/ErsatzTV.Core/Api/MediaSources/LocalLibraryPathResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/LocalLibraryPathResponseModel.cs
new file mode 100644
index 000000000..9fd9084c0
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/LocalLibraryPathResponseModel.cs
@@ -0,0 +1,3 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record LocalLibraryPathResponseModel(int Id, string Path, int MediaItemCount);
diff --git a/ErsatzTV.Core/Api/MediaSources/LocalLibraryResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/LocalLibraryResponseModel.cs
new file mode 100644
index 000000000..7bb4bb8d2
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/LocalLibraryResponseModel.cs
@@ -0,0 +1,5 @@
+using ErsatzTV.Core.Domain;
+
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record LocalLibraryResponseModel(int Id, string Name, LibraryMediaKind MediaKind, bool IsLocked);
diff --git a/ErsatzTV.Core/Api/MediaSources/LocalPathCheckResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/LocalPathCheckResponseModel.cs
new file mode 100644
index 000000000..d8e192c96
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/LocalPathCheckResponseModel.cs
@@ -0,0 +1,3 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record LocalPathCheckResponseModel(bool Exists);
diff --git a/ErsatzTV.Core/Api/MediaSources/PathReplacementResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/PathReplacementResponseModel.cs
new file mode 100644
index 000000000..40883f44a
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/PathReplacementResponseModel.cs
@@ -0,0 +1,3 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record PathReplacementResponseModel(int Id, string RemotePath, string LocalPath);
diff --git a/ErsatzTV.Core/Api/MediaSources/PlexPinFlowResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/PlexPinFlowResponseModel.cs
new file mode 100644
index 000000000..141db29f3
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/PlexPinFlowResponseModel.cs
@@ -0,0 +1,3 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record PlexPinFlowResponseModel(string AuthUrl);
diff --git a/ErsatzTV.Core/Api/MediaSources/RemoteConnectionResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/RemoteConnectionResponseModel.cs
new file mode 100644
index 000000000..c514a1af6
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/RemoteConnectionResponseModel.cs
@@ -0,0 +1,5 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+// NEVER include the raw API key in this DTO — the secure connection contract (design #202 finding 1)
+// requires the key never leave the server; callers only learn whether one is configured.
+public record RemoteConnectionResponseModel(string Address, bool HasApiKey);
diff --git a/ErsatzTV.Core/Api/MediaSources/RemoteLibraryResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/RemoteLibraryResponseModel.cs
new file mode 100644
index 000000000..307f0b853
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/RemoteLibraryResponseModel.cs
@@ -0,0 +1,5 @@
+using ErsatzTV.Core.Domain;
+
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record RemoteLibraryResponseModel(int Id, string Name, LibraryMediaKind MediaKind, bool ShouldSyncItems);
diff --git a/ErsatzTV.Core/Api/MediaSources/RemoteMediaSourceItemResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/RemoteMediaSourceItemResponseModel.cs
new file mode 100644
index 000000000..3e18cc656
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/RemoteMediaSourceItemResponseModel.cs
@@ -0,0 +1,3 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record RemoteMediaSourceItemResponseModel(int Id, string Name, string Address);
diff --git a/ErsatzTV.Core/Api/MediaSources/RemoteMediaSourceStateResponseModel.cs b/ErsatzTV.Core/Api/MediaSources/RemoteMediaSourceStateResponseModel.cs
new file mode 100644
index 000000000..0654d7bf7
--- /dev/null
+++ b/ErsatzTV.Core/Api/MediaSources/RemoteMediaSourceStateResponseModel.cs
@@ -0,0 +1,6 @@
+namespace ErsatzTV.Core.Api.MediaSources;
+
+public record RemoteMediaSourceStateResponseModel(
+ bool IsAuthorized,
+ bool IsLocked,
+ List Servers);
diff --git a/ErsatzTV.Core/Domain/Collection/Collection.cs b/ErsatzTV.Core/Domain/Collection/Collection.cs
index d882e0b16..04d71218f 100644
--- a/ErsatzTV.Core/Domain/Collection/Collection.cs
+++ b/ErsatzTV.Core/Domain/Collection/Collection.cs
@@ -3,9 +3,10 @@
namespace ErsatzTV.Core.Domain;
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
-public class Collection
+public class Collection : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public string Name { get; set; }
public bool UseCustomPlaybackOrder { get; set; }
public List MediaItems { get; set; }
diff --git a/ErsatzTV.Core/Domain/Collection/MultiCollection.cs b/ErsatzTV.Core/Domain/Collection/MultiCollection.cs
index e14c05744..741c7e1c2 100644
--- a/ErsatzTV.Core/Domain/Collection/MultiCollection.cs
+++ b/ErsatzTV.Core/Domain/Collection/MultiCollection.cs
@@ -3,9 +3,10 @@
namespace ErsatzTV.Core.Domain;
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
-public class MultiCollection
+public class MultiCollection : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public string Name { get; set; }
public List Collections { get; set; }
public List SmartCollections { get; set; }
diff --git a/ErsatzTV.Core/Domain/Collection/Playlist.cs b/ErsatzTV.Core/Domain/Collection/Playlist.cs
index fd3e204f5..411409918 100644
--- a/ErsatzTV.Core/Domain/Collection/Playlist.cs
+++ b/ErsatzTV.Core/Domain/Collection/Playlist.cs
@@ -1,8 +1,9 @@
namespace ErsatzTV.Core.Domain;
-public class Playlist
+public class Playlist : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public int PlaylistGroupId { get; set; }
public PlaylistGroup PlaylistGroup { get; set; }
public string Name { get; set; }
diff --git a/ErsatzTV.Core/Domain/Collection/RerunCollection.cs b/ErsatzTV.Core/Domain/Collection/RerunCollection.cs
index e6ef7db34..e4fdebe68 100644
--- a/ErsatzTV.Core/Domain/Collection/RerunCollection.cs
+++ b/ErsatzTV.Core/Domain/Collection/RerunCollection.cs
@@ -3,9 +3,10 @@
namespace ErsatzTV.Core.Domain;
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
-public class RerunCollection
+public class RerunCollection : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public string Name { get; set; }
public CollectionType CollectionType { get; set; }
public int? CollectionId { get; set; }
diff --git a/ErsatzTV.Core/Domain/IVersionedAggregate.cs b/ErsatzTV.Core/Domain/IVersionedAggregate.cs
new file mode 100644
index 000000000..c863496d5
--- /dev/null
+++ b/ErsatzTV.Core/Domain/IVersionedAggregate.cs
@@ -0,0 +1,12 @@
+namespace ErsatzTV.Core.Domain;
+
+///
+/// A root aggregate that carries an integer optimistic-concurrency token (issue #253).
+/// The token is exposed as a strong ETag on the aggregate's GET, checked against a
+/// PUT's If-Match header (mismatch → 412 Precondition Failed), and bumped on every
+/// successful write so a stale second writer is rejected and every other client's ETag rotates.
+///
+public interface IVersionedAggregate
+{
+ int Version { get; set; }
+}
diff --git a/ErsatzTV.Core/Domain/Playout.cs b/ErsatzTV.Core/Domain/Playout.cs
index f83ee357e..128c60a79 100644
--- a/ErsatzTV.Core/Domain/Playout.cs
+++ b/ErsatzTV.Core/Domain/Playout.cs
@@ -2,9 +2,10 @@
namespace ErsatzTV.Core.Domain;
-public class Playout
+public class Playout : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public int ChannelId { get; set; }
public Channel Channel { get; set; }
public int? ProgramScheduleId { get; set; }
diff --git a/ErsatzTV.Core/Domain/ProgramSchedule.cs b/ErsatzTV.Core/Domain/ProgramSchedule.cs
index a29bdc98b..422dd53a3 100644
--- a/ErsatzTV.Core/Domain/ProgramSchedule.cs
+++ b/ErsatzTV.Core/Domain/ProgramSchedule.cs
@@ -2,9 +2,10 @@
namespace ErsatzTV.Core.Domain;
-public class ProgramSchedule
+public class ProgramSchedule : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public string Name { get; set; }
public bool KeepMultiPartEpisodesTogether { get; set; }
public bool TreatCollectionsAsShows { get; set; }
diff --git a/ErsatzTV.Core/Domain/Scheduling/Block.cs b/ErsatzTV.Core/Domain/Scheduling/Block.cs
index 645c34e80..16373b9bf 100644
--- a/ErsatzTV.Core/Domain/Scheduling/Block.cs
+++ b/ErsatzTV.Core/Domain/Scheduling/Block.cs
@@ -1,8 +1,9 @@
namespace ErsatzTV.Core.Domain.Scheduling;
-public class Block
+public class Block : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public int BlockGroupId { get; set; }
public BlockGroup BlockGroup { get; set; }
public string Name { get; set; }
diff --git a/ErsatzTV.Core/Domain/Scheduling/DecoTemplate.cs b/ErsatzTV.Core/Domain/Scheduling/DecoTemplate.cs
index a33b283f8..67bba9681 100644
--- a/ErsatzTV.Core/Domain/Scheduling/DecoTemplate.cs
+++ b/ErsatzTV.Core/Domain/Scheduling/DecoTemplate.cs
@@ -1,8 +1,9 @@
namespace ErsatzTV.Core.Domain.Scheduling;
-public class DecoTemplate
+public class DecoTemplate : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public int DecoTemplateGroupId { get; set; }
public DecoTemplateGroup DecoTemplateGroup { get; set; }
public string Name { get; set; }
diff --git a/ErsatzTV.Core/Domain/Scheduling/Template.cs b/ErsatzTV.Core/Domain/Scheduling/Template.cs
index 89030c537..d03efe95f 100644
--- a/ErsatzTV.Core/Domain/Scheduling/Template.cs
+++ b/ErsatzTV.Core/Domain/Scheduling/Template.cs
@@ -1,8 +1,9 @@
namespace ErsatzTV.Core.Domain.Scheduling;
-public class Template
+public class Template : IVersionedAggregate
{
public int Id { get; set; }
+ public int Version { get; set; }
public int TemplateGroupId { get; set; }
public TemplateGroup TemplateGroup { get; set; }
public string Name { get; set; }
diff --git a/ErsatzTV.Core/Errors/PreconditionFailedError.cs b/ErsatzTV.Core/Errors/PreconditionFailedError.cs
new file mode 100644
index 000000000..5c738427e
--- /dev/null
+++ b/ErsatzTV.Core/Errors/PreconditionFailedError.cs
@@ -0,0 +1,14 @@
+namespace ErsatzTV.Core.Errors;
+
+///
+/// A raised when an optimistic-concurrency precondition fails — the
+/// caller's If-Match version no longer matches the stored aggregate Version
+/// (issue #253). REST endpoints map this to HTTP 412 Precondition Failed; it is distinct from
+/// the 409 Conflict raised when a mutation races a background build lock (api-conventions §3a).
+///
+public class PreconditionFailedError : BaseError
+{
+ public PreconditionFailedError(string value) : base(value)
+ {
+ }
+}
diff --git a/ErsatzTV.Core/Interfaces/Repositories/ILibraryRepository.cs b/ErsatzTV.Core/Interfaces/Repositories/ILibraryRepository.cs
index 7cdba2aa7..afa8038de 100644
--- a/ErsatzTV.Core/Interfaces/Repositories/ILibraryRepository.cs
+++ b/ErsatzTV.Core/Interfaces/Repositories/ILibraryRepository.cs
@@ -7,6 +7,14 @@ public interface ILibraryRepository
Task Add(LibraryPath libraryPath);
Task