E2: correzioni della revisione delle copie esterne
verifica / controlli (push) Canceled after 0s
verifica / prove (push) Canceled after 0s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s

- Nome libero scelto prima di scrivere, libero sul disco e nel database;
  una riga orfana sul nome diventa «Tolto» (guardando il suo percorso,
  anche se differisce solo per le maiuscole): prima la copia finiva
  «Non riuscito» con il file già scritto, o toglieva la copia buona.
- «Controlla le copie» rilegge la radice e riguarda i file mancanti;
  con il disco staccato si ferma e mette in pausa senza segnare nulla.
- Su Linux lo spostamento sul nome finale non sostituisce mai un file
  (renameat2 RENAME_NOREPLACE, poi link e unlink).
- Le copie in coda di un lavoro interrotto diventano «Interrotta» e si
  riprendono; il permesso dei lavori lunghi si tiene già nel piano.
- «Superato» con il file di nuovo in libreria: filtro, piano e «Copia di
  nuovo» d'accordo; l'adozione ravviva la riga invece di fallire.
- «Una copia sola» con una regola sola in filtro, piano, visualizzatore
  e copiatore (solo copie di un altro account in cartelle in uso).
- Controllo della cartella per identità vera (percorso finale, realpath,
  dispositivo di mountinfo): riconosce collegamenti e bind mount di una
  sottocartella della libreria.
- Sfoglia delle cartelle con tempi massimi; «Nessuna cartella» solo se
  non ce n'è; «In copia…» nel visualizzatore; numero e fuoco stabili in
  «Copia di nuovo anche…»; una sola lettura per volta nella Dashboard.
- Prove dell'interfaccia indipendenti dall'ora e dal file scelto; prove
  nuove in ExportReviewTests, ExportFolderCheckTests, ExportRootTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 17:02:06 +01:00
1 parent 28c7f814b1
commit 36ad5c6f9d
28 files changed
+1314 -112

No files matched your search

+111 -23
View File
@@ -117,15 +117,29 @@ public sealed class ExportService : IAsyncDisposable
public async Task<ExportStart> StartAsync(ExportJobRequest request, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(request);
var held = new LeaseHolder();
lock (_gate)
{
EnsureIdle();
// The long-work gate is held from the plan on (§4.10 «esportazione, importazione e ricostruzione non girano
// insieme»): a rebuild or an import cannot start while the runs and their items are being recorded.
if (_env.Gate is { } gate)
{
if (!gate.TryEnter(LongWorkKind.Export, out var lease, out var busy))
{
throw new InvalidOperationException(LongWorkGate.BusyMessage(LongWorkKind.Export, busy!.Value));
}
held.Lease = lease;
}
_starting = true; // a second «Copia in…» meanwhile records nothing
}
try
{
return await StartReservedAsync(request, ct).ConfigureAwait(false);
return await StartReservedAsync(request, held, ct).ConfigureAwait(false);
}
finally
{
@@ -133,10 +147,12 @@ public sealed class ExportService : IAsyncDisposable
{
_starting = false;
}
held.Lease?.Dispose(); // not handed to a job: nothing to copy, or the start failed
}
}
private async Task<ExportStart> StartReservedAsync(ExportJobRequest request, CancellationToken ct)
private async Task<ExportStart> StartReservedAsync(ExportJobRequest request, LeaseHolder held, CancellationToken ct)
{
var effective = await Destinations.ResolveAllAsync(ct).ConfigureAwait(false);
var settings = await ExportSettings.LoadAsync(_env.Storage.Settings, ct).ConfigureAwait(false);
@@ -206,7 +222,8 @@ public sealed class ExportService : IAsyncDisposable
lock (_gate)
{
_starting = false;
StartCopyJob(ordered.Select(r => r.Id).ToList());
StartCopyJob(ordered.Select(r => r.Id).ToList(), held.Lease);
held.Lease = null; // the job owns it now
}
}
catch
@@ -463,26 +480,37 @@ public sealed class ExportService : IAsyncDisposable
}
after = page[^1].Id;
if (!Directory.Exists(destination.RootPath))
if (!await RootAnswersAsync(destination, ct).ConfigureAwait(false))
{
// The disk went away during the check: nothing is «Tolto» because of that.
var gone = await Copier.CheckDestinationAsync(destination, ct).ConfigureAwait(false) ?? $"{label} non è raggiungibile.";
await ExportPause.PauseAsync(_env, destination, gone).ConfigureAwait(false);
await PauseCheckAsync(destination, label, ct).ConfigureAwait(false);
Report(ExportPhase.Finished, done);
return;
}
var missing = new List<long>();
var missing = new List<ExportCopy>();
foreach (var copy in page)
{
ct.ThrowIfCancellationRequested();
if (copy.RelativePath is not { } path || !FileExists(destination.RootPath, path))
{
missing.Add(copy.Id);
missing.Add(copy);
}
}
removed += await exports.MarkCopiesRemovedAsync(missing, _env.Clock.Now, CancellationToken.None).ConfigureAwait(false);
// The disk may have gone away while the page was read (decision of 2026-11-27, §4.10): the root is asked
// again after the files and before anything is marked, and a missing file is looked for once more.
if (missing.Count > 0 && !await RootAnswersAsync(destination, ct).ConfigureAwait(false))
{
await PauseCheckAsync(destination, label, ct).ConfigureAwait(false);
Report(ExportPhase.Finished, done);
return;
}
var gone = missing
.Where(copy => copy.RelativePath is not { } path || !FileExists(destination.RootPath, path))
.Select(copy => copy.Id)
.ToList();
removed += await exports.MarkCopiesRemovedAsync(gone, _env.Clock.Now, CancellationToken.None).ConfigureAwait(false);
done += page.Count;
Report(ExportPhase.Checking, done);
}
@@ -501,6 +529,26 @@ public sealed class ExportService : IAsyncDisposable
Report(ExportPhase.Finished, done);
}
/// <summary>The root of the destination is there, asked within the folder-check time (a dead share must not block).</summary>
private async Task<bool> RootAnswersAsync(ExportDestination destination, CancellationToken ct)
{
try
{
return await Task.Run(() => Directory.Exists(destination.RootPath), ct).WaitAsync(_env.FolderCheckTimeout, ct).ConfigureAwait(false);
}
catch (TimeoutException)
{
return false;
}
}
/// <summary>The disk went away during «Controlla le copie»: nothing is «Tolto» because of that, the destination pauses.</summary>
private async Task PauseCheckAsync(ExportDestination destination, string label, CancellationToken ct)
{
var problem = await Copier.CheckDestinationAsync(destination, ct).ConfigureAwait(false) ?? $"{label} non è raggiungibile.";
await ExportPause.PauseAsync(_env, destination, problem).ConfigureAwait(false);
}
private bool FileExists(string root, string relativePath)
{
try
@@ -561,25 +609,59 @@ public sealed class ExportService : IAsyncDisposable
}
}
private void StartCopyJob(IReadOnlyList<long> runIds) =>
StartJob(runIds, async (progress, token) =>
{
foreach (var runId in runIds)
private void StartCopyJob(IReadOnlyList<long> runIds, IDisposable? lease = null) =>
StartJob(
runIds,
async (progress, token) =>
{
token.ThrowIfCancellationRequested();
var next = 0;
try
{
await Copier.CopyAsync(runId, progress, token).ConfigureAwait(false);
for (; next < runIds.Count; next++)
{
token.ThrowIfCancellationRequested();
try
{
await Copier.CopyAsync(runIds[next], progress, token).ConfigureAwait(false);
}
catch (Exception ex) when (ex is not OperationCanceledException || !token.IsCancellationRequested)
{
// Stored with the run (Interrupted, with its error); the next destination still gets its files.
LastJobError = ExportText.ErrorText(ex);
}
}
}
catch (Exception ex) when (ex is not OperationCanceledException || !token.IsCancellationRequested)
finally
{
// Stored with the run (Interrupted, with its error); the next destination still gets its files.
LastJobError = ExportText.ErrorText(ex);
// «Interrompi» (or «Annulla», or the end of Febe) stopped the job before its later destinations: those
// runs were recorded as running and nothing runs them now. They become «interrotto», resumable, as
// RecoverAsync would make them at the next start.
await InterruptQueuedAsync(runIds.Skip(next)).ConfigureAwait(false);
}
},
lease);
/// <summary>Runs of a stopped job that were never reached and are still recorded as running become «interrotto».</summary>
private async Task InterruptQueuedAsync(IEnumerable<long> runIds)
{
foreach (var runId in runIds)
{
try
{
if (await _env.Storage.Exports.GetRunAsync(runId, CancellationToken.None).ConfigureAwait(false) is { State: ExportRunState.Running } run)
{
await _env.Storage.Exports.UpdateRunAsync(run with { State = ExportRunState.Interrupted, LastError = null }, CancellationToken.None).ConfigureAwait(false);
}
}
});
catch (Exception ex) when (ex is not OutOfMemoryException)
{
// RecoverAsync makes it «interrotto» at the next start.
}
}
}
private void StartJob(IReadOnlyList<long> runIds, Func<IProgress<ExportProgress>, CancellationToken, Task> work)
/// <summary>Starts a job; <paramref name="held"/> is a lease of the gate already taken (the job owns it once started).</summary>
private void StartJob(IReadOnlyList<long> runIds, Func<IProgress<ExportProgress>, CancellationToken, Task> work, IDisposable? held = null)
{
lock (_gate)
{
@@ -588,8 +670,8 @@ public sealed class ExportService : IAsyncDisposable
throw new InvalidOperationException(BusyText);
}
IDisposable? lease = null;
if (_env.Gate is { } gate && !gate.TryEnter(LongWorkKind.Export, out lease, out var busy))
var lease = held;
if (lease is null && _env.Gate is { } gate && !gate.TryEnter(LongWorkKind.Export, out lease, out var busy))
{
throw new InvalidOperationException(LongWorkGate.BusyMessage(LongWorkKind.Export, busy!.Value));
}
@@ -662,6 +744,12 @@ public sealed class ExportService : IAsyncDisposable
private sealed record Job(IReadOnlyList<long> RunIds, CancellationTokenSource Cancellation, Task Task);
/// <summary>A lease of the long-work gate on its way from <see cref="StartAsync"/> to the job.</summary>
private sealed class LeaseHolder
{
public IDisposable? Lease { get; set; }
}
private sealed class Reporter(ExportService owner) : IProgress<ExportProgress>
{
private (ExportPhase, long?)? _phase;