Ricostruzione: la prova aspetta il database tenuto per un attimo su Windows

TestLibrary.LoseDatabaseAsync elimina febe.sqlite appena chiuso. Su Windows un file aperto da un
altro programma non si elimina, e con Defender attivo succedeva circa 3 volte su 40 esecuzioni
delle prove di libreria: il file era libero dopo 6-17 ms e nessun processo risultava tenerlo,
quindi non è un collegamento di Febe rimasto aperto. Su Windows l'eliminazione che trova il file
in uso si ripete ogni 50 ms per al più 5 s; su Linux, dove eliminare un file aperto riesce
sempre, non cambia nulla.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-20 13:09:19 +02:00
1 parent e035cfd20a
commit f7de7f5642
2 files changed
+25 -1

No files matched your search

+24 -1
View File
@@ -63,13 +63,36 @@ internal sealed class TestLibrary : IAsyncDisposable
await Db.DisposeAsync();
foreach (var suffix in new[] { string.Empty, "-wal", "-shm" })
{
File.Delete(Data.Database + suffix);
await DeleteClosedFileAsync(Data.Database + suffix);
}
Db = await FebeDatabase.OpenAsync(Data.Root);
Ingest = new LibraryIngest(Db, Layout, LibraryNaming.Default, Journal, Clock, Thumbnails, Index);
}
/// <summary>
/// Deletes a file Febe has already closed. On Windows a file that another program holds open cannot be deleted, and a
/// database just written is sometimes held for a few milliseconds by a program that scans new files (the real-time
/// antivirus): that sharing violation is waited out (at most 5 s). On Linux a delete never meets one, so the first
/// attempt is the only one.
/// </summary>
private static async Task DeleteClosedFileAsync(string path)
{
const int SharingViolation = unchecked((int)0x80070020);
for (var attempt = 1; ; attempt++)
{
try
{
File.Delete(path);
return;
}
catch (IOException ex) when (OperatingSystem.IsWindows() && ex.HResult == SharingViolation && attempt < 100)
{
await Task.Delay(50);
}
}
}
public ValueTask DisposeAsync() => Db.DisposeAsync();
}