E2: motore delle copie esterne (porta, destinazioni, piano, copia)

Prima metà della tappa E2 «Copie esterne» (#58), parte Core e Data:

- porta del lavoro lungo: importazione, copia e ricostruzione mai insieme;
- radice /esporta in Docker con mountinfo, controllo delle cartelle con
  il file di prova, destinazioni con «Esporta questo account» acceso se
  Alberto non ha mai scelto (decisione del 27/11/2026);
- filtro «Copie», segni delle tessere e conteggi dell'account sui soli
  file dovuti (D3);
- percorsi «Come la libreria», segmento dell'account nella cartella
  generale, 240 caratteri, storia in evidenza;
- piano di «Copia in…», un lavoro per destinazione, copia in .part con
  SHA-256 riletto dal disco, nome libero, mai sovrascrivere, adozione
  per percorso, pausa della destinazione su prova, spazio e FAT32,
  attesa fuori dalle sessioni del motore, ripresa e recupero;
- .part rimossi solo nelle cartelle degli elementi di lavori non finiti;
- «Tolto» e «Superato» (agganci in importazione, scaricamenti,
  doppioni e ricostruzione), mai ricopiati da soli;
- rapporti e testi in italiano, prove del lavoro di copia.

Interfaccia, API e composizione restano alla parte successiva.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 10:55:29 +01:00
1 parent 213b89a618
commit a112c92893
41 files changed
+5370 -27

No files matched your search

+22 -6
View File
@@ -156,9 +156,10 @@ public sealed class FolderSizes(IClock clock)
/// <summary>
/// «Ricostruisci il database dalla libreria» (spec §8.5) as a background job with its progress and its last report,
/// one at a time. It never moves, renames or deletes a file (rule 12).
/// one at a time, never together with an import or a copy to external folders (the shared <see cref="LongWorkGate"/>,
/// spec §4.10). It never moves, renames or deletes a file (rule 12).
/// </summary>
public sealed class RebuildJob(IFebeStorage storage, FebeLibrary library, IClock clock, LibraryChanges changes)
public sealed class RebuildJob(IFebeStorage storage, FebeLibrary library, IClock clock, LibraryChanges changes, LongWorkGate gate)
{
private readonly Lock _gate = new();
private Task? _task;
@@ -176,18 +177,32 @@ public sealed class RebuildJob(IFebeStorage storage, FebeLibrary library, IClock
}
}
/// <summary>Starts the rebuild; false when one is already running.</summary>
public bool TryStart()
/// <summary>Starts the rebuild; false when one is already running or another long job holds the gate.</summary>
public bool TryStart() => TryStart(out _);
/// <summary>
/// Starts the rebuild; false, with the Italian reason in <paramref name="busy"/>, when a rebuild, an import or a copy
/// to external folders is running.
/// </summary>
public bool TryStart(out string? busy)
{
lock (_gate)
{
if (_task is { IsCompleted: false })
{
busy = LongWorkGate.BusyMessage(LongWorkKind.Rebuild, LongWorkKind.Rebuild);
return false;
}
if (!gate.TryEnter(LongWorkKind.Rebuild, out var lease, out var holder))
{
busy = LongWorkGate.BusyMessage(LongWorkKind.Rebuild, holder!.Value);
return false;
}
busy = null;
State = RebuildState.Idle with { Running = true, StartedAt = clock.Now };
_task = Task.Run(RunAsync);
_task = Task.Run(() => RunAsync(lease));
return true;
}
}
@@ -195,8 +210,9 @@ public sealed class RebuildJob(IFebeStorage storage, FebeLibrary library, IClock
/// <summary>Waits for the running rebuild (tests).</summary>
public Task WaitAsync() => _task ?? Task.CompletedTask;
private async Task RunAsync()
private async Task RunAsync(IDisposable lease)
{
using var held = lease;
var progress = new SyncProgress<RebuildProgress>(p => State = State with { Folder = p.Folder, FoldersDone = p.FoldersDone, FoldersTotal = p.FoldersTotal, FilesChecked = p.FilesChecked });
try
{