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
@@ -0,0 +1,138 @@
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Engine;
|
||||
using Febe.Core.Storage;
|
||||
|
||||
namespace Febe.Core.Export;
|
||||
|
||||
/// <summary>
|
||||
/// Texts of the copies to external folders for Alberto (spec §4.10, §10.4): sentence case, dots for thousands, the same
|
||||
/// names everywhere. Notes are stored in <c>export_item.note</c> as English codes (<see cref="Notes"/>) and shown with
|
||||
/// <see cref="Note"/>.
|
||||
/// </summary>
|
||||
public static class ExportText
|
||||
{
|
||||
/// <summary>The codes of <c>export_item.note</c>.</summary>
|
||||
public static class Notes
|
||||
{
|
||||
public const string SourceMissing = "SourceMissing";
|
||||
public const string AccountRemoved = "AccountRemoved";
|
||||
public const string Removed = "Removed";
|
||||
public const string Superseded = "Superseded";
|
||||
public const string CopiedForAnotherAccount = "CopiedForAnotherAccount";
|
||||
public const string SourceChanged = "SourceChanged";
|
||||
public const string TooLargeForFileSystem = "TooLargeForFileSystem";
|
||||
public const string NameTaken = "NameTaken";
|
||||
public const string PathTaken = "PathTaken";
|
||||
public const string NotExported = "NotExported";
|
||||
}
|
||||
|
||||
/// <summary>Name of the state of a file of a job.</summary>
|
||||
public static string State(ExportItemState state) => state switch
|
||||
{
|
||||
ExportItemState.Pending => "In attesa",
|
||||
ExportItemState.Copied => "Copiato",
|
||||
ExportItemState.Adopted => "Adottato",
|
||||
ExportItemState.AlreadyCopied => "Già copiato",
|
||||
ExportItemState.Skipped => "Saltato",
|
||||
ExportItemState.Missing => "File non presente in libreria",
|
||||
ExportItemState.Failed => "Non riuscito",
|
||||
_ => state.ToString(),
|
||||
};
|
||||
|
||||
/// <summary>Name of the state of a copy.</summary>
|
||||
public static string CopyState(ExportCopyState state) => state switch
|
||||
{
|
||||
ExportCopyState.Copied => "Copiato",
|
||||
ExportCopyState.Removed => "Tolto",
|
||||
ExportCopyState.Superseded => "Superato",
|
||||
ExportCopyState.Failed => "Non riuscito",
|
||||
_ => state.ToString(),
|
||||
};
|
||||
|
||||
/// <summary>The Italian text of a note code; null for none; an unknown code is shown as it is.</summary>
|
||||
public static string? Note(string? code) => code switch
|
||||
{
|
||||
null or "" => null,
|
||||
Notes.SourceMissing => "File non presente in libreria",
|
||||
Notes.AccountRemoved => "L'account è stato rimosso",
|
||||
Notes.Removed => "Tolto dalla destinazione: non si ricopia da solo («Copia di nuovo»)",
|
||||
Notes.Superseded => "Superato da un file nuovo della libreria: non si ricopia da solo",
|
||||
Notes.CopiedForAnotherAccount => "Già copiato per un altro account («Una copia sola»)",
|
||||
Notes.SourceChanged => "Il file della libreria non corrisponde a quello registrato",
|
||||
Notes.TooLargeForFileSystem => "Più grande di 4 GB: il disco FAT32 non lo accetta",
|
||||
Notes.NameTaken => "Nome già occupato da un altro file: copiato con un nome libero",
|
||||
Notes.PathTaken => "Percorso preso nel frattempo: riprova",
|
||||
Notes.NotExported => "Non si copia qui: «Esporta questo account» è spento, o il file va in un'altra cartella",
|
||||
_ => code,
|
||||
};
|
||||
|
||||
/// <summary>«1 file copiato», «1.204 file copiati».</summary>
|
||||
public static string Count(int count, string one, string many) => count == 1 ? "1 " + one : ItalianText.Number(count) + " " + many;
|
||||
|
||||
/// <summary>The event written when a job ends: «Copia in Disco USB finita: 120 file copiati, 30 già copiati.»</summary>
|
||||
public static string CompletionMessage(ExportRunSummary summary, ExportDestination destination)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(summary);
|
||||
ArgumentNullException.ThrowIfNull(destination);
|
||||
int Of(ExportItemState s) => summary.ByState.GetValueOrDefault(s);
|
||||
var parts = new List<string> { Count(Of(ExportItemState.Copied) + Of(ExportItemState.Adopted), "file copiato", "file copiati") };
|
||||
if (Of(ExportItemState.AlreadyCopied) > 0)
|
||||
{
|
||||
parts.Add(Count(Of(ExportItemState.AlreadyCopied), "già copiato", "già copiati"));
|
||||
}
|
||||
|
||||
if (Of(ExportItemState.Skipped) > 0)
|
||||
{
|
||||
parts.Add(Count(Of(ExportItemState.Skipped), "saltato", "saltati"));
|
||||
}
|
||||
|
||||
if (Of(ExportItemState.Missing) > 0)
|
||||
{
|
||||
parts.Add(Count(Of(ExportItemState.Missing), "non presente in libreria", "non presenti in libreria"));
|
||||
}
|
||||
|
||||
if (Of(ExportItemState.Failed) > 0)
|
||||
{
|
||||
parts.Add(Count(Of(ExportItemState.Failed), "non riuscito", "non riusciti"));
|
||||
}
|
||||
|
||||
return $"Copia in {ExportDestinations.Label(destination)} finita: {string.Join(", ", parts)}.";
|
||||
}
|
||||
|
||||
/// <summary>The event of «Controlla le copie».</summary>
|
||||
public static string CheckMessage(int checkedCopies, int removed, ExportDestination destination)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(destination);
|
||||
var text = $"Controllate {ItalianText.Number(checkedCopies)} copie in {ExportDestinations.Label(destination)}: ";
|
||||
return text + (removed == 0 ? "ci sono tutte." : $"{Count(removed, "non c'è più (tolta)", "non ci sono più (tolte)")}.");
|
||||
}
|
||||
|
||||
/// <summary>The space is not enough for the next file (decision D16).</summary>
|
||||
public static string NoSpace(ExportDestination destination, long free, string file, long bytes) =>
|
||||
$"Su {ExportDestinations.Label(destination)} restano {ItalianText.Bytes(free)}: per copiare {file} ({ItalianText.Bytes(bytes)}) serve più spazio, "
|
||||
+ $"con un margine di {ItalianText.Bytes(ExportSpace.Margin)}. Libera spazio, poi riprendi.";
|
||||
|
||||
/// <summary>The disk said it is full.</summary>
|
||||
public static string DiskFull(ExportDestination destination) =>
|
||||
$"Su {ExportDestinations.Label(destination)} non c'è più spazio: libera spazio, poi riprendi.";
|
||||
|
||||
/// <summary>A file over the FAT32 limit.</summary>
|
||||
public static string TooLarge(long bytes) =>
|
||||
$"Il file pesa {ItalianText.Bytes(bytes)}: su un disco FAT32 un file non può superare 4 GB.";
|
||||
|
||||
/// <summary>The destination was retired while a job used it.</summary>
|
||||
public const string RetiredDestination = "La cartella è stata tolta.";
|
||||
|
||||
/// <summary>An error for Alberto, without paths of secrets: the message of a file error, or a generic sentence.</summary>
|
||||
public static string ErrorText(Exception ex)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(ex);
|
||||
return ex switch
|
||||
{
|
||||
ExportFolderException folder => folder.Message,
|
||||
IOException io => $"Errore di lettura o scrittura: {io.Message}",
|
||||
UnauthorizedAccessException => "Febe non ha il permesso di scrivere nella cartella: controlla i permessi.",
|
||||
_ => $"Errore inatteso ({ex.GetType().Name}): riprova; se si ripete, segnalalo.",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user