Fix Critical: IndexSystem lock races and TrackRepository.Update silent-create
- Replace object lock with SemaphoreSlim(1,1) on both DirectoryIndexDirectory and VaultIndexDirectory; SaveIndexAsync now executes inside the semaphore so mutate+persist is atomic - ReloadIndexAsync acquires the semaphore before LoadIndexAsync so disk load and in-memory swap are atomic with respect to concurrent writes - HasIndexEntry and GetEntryMetadata converted to async Task with WaitAsync; MediaVault.GetEntryAsync call sites updated accordingly - TrackRepository.Update throws InvalidOperationException when Id not found instead of silently calling Create; service layer catches and wraps as fail result
This commit is contained in:
@@ -92,7 +92,7 @@ public class FileDatabaseTests
|
||||
// Assert
|
||||
var vault = _fileDatabase.GetVault(TestData.TestKeys.ImageVaultKey);
|
||||
Assert.That(vault, Is.Not.Null, "Vault should not be null");
|
||||
Assert.That(vault!.HasIndexEntry(TestData.TestKeys.TestImageEntry), Is.True,
|
||||
Assert.That(await vault!.HasIndexEntry(TestData.TestKeys.TestImageEntry), Is.True,
|
||||
"Added image should be in the index");
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class FileDatabaseTests
|
||||
Assert.That(reloadedDatabase.GetIndexSize(), Is.EqualTo(1), "Index count should be 1");
|
||||
|
||||
// Verify vault exists
|
||||
Assert.That(reloadedDatabase.HasIndexEntry(TestData.TestKeys.ImageVaultKey), Is.True,
|
||||
Assert.That(await reloadedDatabase.HasIndexEntry(TestData.TestKeys.ImageVaultKey), Is.True,
|
||||
"Vault should be present in index");
|
||||
Assert.That(reloadedDatabase.HasVault(TestData.TestKeys.ImageVaultKey), Is.True,
|
||||
"Vault should be present in vault collection");
|
||||
|
||||
Reference in New Issue
Block a user