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:
1 parent
213b89a618
commit
a112c92893
41 files changed
+5370
-27
No files matched your search
@@ -231,14 +231,16 @@ public static class SettingsApi
|
||||
throw new BadRequestException("Per confermare scrivi la parola «ricostruisci».");
|
||||
}
|
||||
|
||||
// An import service built without the shared gate (a composition of tests) is still checked by itself.
|
||||
if ((await import.GetAsync(ct).ConfigureAwait(false)).ActiveRunId is not null)
|
||||
{
|
||||
throw new BadRequestException("C'è un'importazione al lavoro: aspetta che finisca, poi ricostruisci.");
|
||||
throw new BadRequestException(LongWorkGate.BusyMessage(LongWorkKind.Rebuild, LongWorkKind.Import));
|
||||
}
|
||||
|
||||
if (!job.TryStart())
|
||||
// The gate covers import, copies to external folders and another rebuild (spec §4.10).
|
||||
if (!job.TryStart(out var busy))
|
||||
{
|
||||
throw new BadRequestException("La ricostruzione è già in corso.");
|
||||
throw new BadRequestException(busy ?? LongWorkGate.BusyMessage(LongWorkKind.Rebuild, LongWorkKind.Rebuild));
|
||||
}
|
||||
|
||||
return ApiHttp.Message("Ricostruzione avviata: Febe rilegge le cartelle degli account e i loro file _febe.jsonl. Nessun file viene spostato o cancellato.");
|
||||
|
||||
@@ -73,10 +73,13 @@ public static class FebeWeb
|
||||
services.TryAddSingleton<IAlertTestSender, NoTelegramSender>();
|
||||
services.TryAddSingleton<IDataFolderChange, FixedDataFolder>();
|
||||
services.TryAddSingleton<FolderSizes>();
|
||||
// One gate for import, copies to external folders and rebuild (spec §4.10); the composition may register its own
|
||||
// instance first, the one its import service already uses.
|
||||
services.TryAddSingleton<LongWorkGate>();
|
||||
services.TryAddSingleton<RebuildJob>();
|
||||
services.TryAddSingleton(sp => sp.GetService<ImportService>() is { } import
|
||||
? new ImportHub(import, sp.GetRequiredService<IClock>(), sp.GetRequiredService<LibraryChanges>())
|
||||
: new ImportHub(sp.GetRequiredService<IFebeStorage>(), sp.GetRequiredService<FebeLibrary>(), sp.GetRequiredService<IClock>(), options, sp.GetRequiredService<LibraryChanges>()));
|
||||
: new ImportHub(sp.GetRequiredService<IFebeStorage>(), sp.GetRequiredService<FebeLibrary>(), sp.GetRequiredService<IClock>(), options, sp.GetRequiredService<LibraryChanges>(), sp.GetRequiredService<LongWorkGate>()));
|
||||
services.AddHttpContextAccessor();
|
||||
if (options.Access == AccessMode.Password && !string.IsNullOrEmpty(options.Password))
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ public sealed class ImportHub : IAsyncDisposable
|
||||
private readonly IClock _clock;
|
||||
private readonly FebeWebOptions? _options;
|
||||
private readonly LibraryChanges _changes;
|
||||
private readonly LongWorkGate? _longWork;
|
||||
private readonly bool _owned;
|
||||
private ImportService? _service;
|
||||
private bool _stale;
|
||||
@@ -35,9 +36,13 @@ public sealed class ImportHub : IAsyncDisposable
|
||||
_service.ProgressChanged += OnProgress;
|
||||
}
|
||||
|
||||
/// <summary>Builds its own service over the library of the web host.</summary>
|
||||
public ImportHub(IFebeStorage storage, FebeLibrary library, IClock clock, FebeWebOptions options, LibraryChanges changes)
|
||||
/// <summary>
|
||||
/// Builds its own service over the library of the web host. <paramref name="longWork"/> is the gate shared with the
|
||||
/// copies to external folders and the rebuild (null: the import alone, as in some tests).
|
||||
/// </summary>
|
||||
public ImportHub(IFebeStorage storage, FebeLibrary library, IClock clock, FebeWebOptions options, LibraryChanges changes, LongWorkGate? longWork = null)
|
||||
{
|
||||
_longWork = longWork;
|
||||
_storage = storage ?? throw new ArgumentNullException(nameof(storage));
|
||||
_library = library ?? throw new ArgumentNullException(nameof(library));
|
||||
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
|
||||
@@ -127,6 +132,7 @@ public sealed class ImportHub : IAsyncDisposable
|
||||
SetFileTimeToPublication = settings.SetFileTimeToPublication,
|
||||
Sources = SourceRoot is { } root ? ImportSourceOptions.Docker(root) : ImportSourceOptions.AnyFolder,
|
||||
DataFolder = library.Data.Root,
|
||||
Gate = _longWork,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user