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

+20 -8
View File
@@ -115,7 +115,12 @@ internal static class ExportFilterSql
return destination == "1" ? $"({Present})" : $"({Present} AND {destination})";
}
/// <summary>The file is copied in its effective destination (or, with «Una copia sola», in any destination in use).</summary>
/// <summary>
/// The file is copied in its effective destination, or, with «Una copia sola», copied for another account still in
/// Febe in a destination in use: the rule of the plan and of the copy (decision of 2026-11-27, «una copia altrove conta
/// solo se è di un altro account»). A copy of the same account in a folder that is no longer its effective one, and a
/// copy whose account was removed, do not count.
/// </summary>
public static string Copied(ExportFilterContext x)
{
if (!x.HasCopies)
@@ -124,10 +129,14 @@ internal static class ExportFilterSql
}
return x.SamePost == SamePostCopies.OneOnly
? $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id IN ({InUse(x)}) AND c.state = 'Copied' AND c.variant <> 'Frame')"
? $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id IN ({InUse(x)}) AND c.state = 'Copied' AND c.variant <> 'Frame' AND {OneOnlyMatch(x)})"
: $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id AND c.state = 'Copied' AND c.variant <> 'Frame')";
}
/// <summary>«Una copia sola»: a copy <c>c</c> counts for the file of <c>e</c> (in a destination in use, tested apart).</summary>
private static string OneOnlyMatch(ExportFilterContext x) =>
$"((c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id) OR (c.account_id IS NOT NULL AND c.account_id <> e.account_id))";
/// <summary>The last copy of the file in its effective destination failed («Non riuscito»): «Copia in…» tries again.</summary>
public static string Failed(ExportFilterContext x) => !x.HasFailed
? "0"
@@ -211,7 +220,7 @@ internal static class ExportFilterSql
LibraryCopiesFilter.NotCopied => Files(NotCopied(x)),
LibraryCopiesFilter.RemovedOrSuperseded => !x.HasHistory
? "0"
: $"+e.id IN (SELECT m2.entry_id FROM export_copy c JOIN media m2 ON m2.sha256 = coalesce(c.superseded_by_sha256, c.source_sha256) "
: $"+e.id IN (SELECT m2.entry_id FROM export_copy c JOIN media m2 ON m2.sha256 IN (c.source_sha256, c.superseded_by_sha256) "
+ $"WHERE c.destination_id IN ({InUse(x)}) AND c.state IN ('Removed', 'Superseded')) AND {Files(Replaced(x))}",
_ => throw new ArgumentOutOfRangeException(nameof(filter), filter, null),
};
@@ -248,7 +257,7 @@ internal static class ExportFilterSql
private static string CopiedEntries(ExportFilterContext x)
{
var match = x.SamePost == SamePostCopies.OneOnly
? string.Empty
? $" AND {OneOnlyMatch(x)}"
: $" AND c.destination_id = {DestinationOf(x)} AND c.account_id = e.account_id";
return "+e.id IN (SELECT m.entry_id FROM export_copy c CROSS JOIN media m CROSS JOIN entry e "
+ $"WHERE c.destination_id IN ({InUse(x)}) AND c.state = 'Copied' AND c.variant <> 'Frame' AND m.sha256 = c.source_sha256 AND e.id = m.entry_id{match} "
@@ -267,14 +276,17 @@ internal static class ExportFilterSql
: Copied(x);
/// <summary>
/// The removed or superseded part of <see cref="Replaced"/>: the copy of this file in the effective destination was
/// removed, or a copy was superseded (or removed) by this file. In bulk each EXISTS sits behind its list of SHA-256.
/// The removed or superseded part of <see cref="Replaced"/>: a copy of this very file in the effective destination
/// was removed or superseded (whether or not it names the file that replaced it: the file can be back in the library
/// in another entry), or a copy was superseded (or removed) by this file. The same rows as the plan reads
/// (<c>GetCopyStatesAsync</c>), so filter, marks, counts and plan agree (D3). In bulk each EXISTS sits behind its list
/// of SHA-256.
/// </summary>
private static string History(ExportFilterContext x, bool bulk)
{
var destination = DestinationOf(x);
var removed = $"EXISTS (SELECT 1 FROM export_copy c WHERE c.source_sha256 = m.sha256 AND c.destination_id = {destination} AND c.account_id = e.account_id "
+ "AND c.state = 'Removed' AND c.superseded_by_sha256 IS NULL)";
+ "AND c.state IN ('Removed', 'Superseded'))";
var superseded = $"EXISTS (SELECT 1 FROM export_copy c WHERE c.superseded_by_sha256 = m.sha256 AND c.destination_id = {destination} AND c.account_id = e.account_id "
+ "AND c.state IN ('Superseded', 'Removed'))";
if (!bulk)
@@ -283,7 +295,7 @@ internal static class ExportFilterSql
}
var inUse = InUse(x);
return $"((m.sha256 IN (SELECT c.source_sha256 FROM export_copy c WHERE c.destination_id IN ({inUse}) AND c.state = 'Removed') AND {removed}) "
return $"((m.sha256 IN (SELECT c.source_sha256 FROM export_copy c WHERE c.destination_id IN ({inUse}) AND c.state IN ('Removed', 'Superseded')) AND {removed}) "
+ $"OR (m.sha256 IN (SELECT c.superseded_by_sha256 FROM export_copy c WHERE c.superseded_by_sha256 IS NOT NULL AND c.destination_id IN ({inUse})) AND {superseded}))";
}
+6 -3
View File
@@ -885,7 +885,8 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
internal const string CopiedElsewhereSql = $"""
SELECT {CopyColumns} FROM export_copy
WHERE source_sha256 = @h AND variant = @v AND format = @f AND state = 'Copied' AND account_id IS NOT NULL
AND destination_id IN (SELECT id FROM export_destination WHERE removed_at IS NULL)
AND (@a IS NULL OR account_id <> @a)
AND destination_id IN (SELECT id FROM export_destination WHERE removed_at IS NULL AND (scope = 'General' OR account_id IS NOT NULL))
ORDER BY id DESC LIMIT 1
""";
@@ -947,11 +948,13 @@ internal sealed class ExportStore(FebeDatabase db) : IExportStore
ct);
}
public Task<ExportCopy?> FindCopiedElsewhereAsync(string sha256, ExportVariant variant, ExportFormat format, CancellationToken ct = default)
public Task<ExportCopy?> FindCopiedElsewhereAsync(string sha256, ExportVariant variant, ExportFormat format, long? exceptAccountId = null, CancellationToken ct = default)
{
var sha = ExportValues.Sha(sha256, nameof(sha256));
return db.ReadAsync(
c => ReadFirst(c.Command(CopiedElsewhereSql).With("@h", sha).With("@v", Sql.Enum(variant)).With("@f", Sql.Enum(format)), ReadCopy),
c => ReadFirst(
c.Command(CopiedElsewhereSql).With("@h", sha).With("@v", Sql.Enum(variant)).With("@f", Sql.Enum(format)).With("@a", Sql.Int(exceptAccountId)),
ReadCopy),
ct);
}