fix(import): say why a photo was not copied with a catalog sentence
A photo the executor could not copy now carries one localized sentence (ImportExecutor.FailureText: its own checks, a full destination, access denied, else "The photo could not be read or copied.") on the Import screen and in the import job's log. The photos a stopped folder or server import never reached show the stop's cause (ImportFailures.Stop: the server's own sentence, not answering, untrusted certificate, card gone, destination full or not writable), and a failed index check reads "The index could not be read or written.". A refusal without words reads as the catalog's sentence. The system's text stays in the log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
11 files changed
+132
-17
No files matched your search
@@ -211,7 +211,8 @@ public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IRea
|
||||
/// </summary>
|
||||
public static class LocalImport
|
||||
{
|
||||
public static async Task<ImportOutcome> RunAsync(ImportPlan plan, IImportSink sink, bool verify, IProgress<ImportProgress>? progress,
|
||||
/// <param name="source">The card or folder as the Devices list names it (a card that leaves is named in each failure).</param>
|
||||
public static async Task<ImportOutcome> RunAsync(ImportPlan plan, IImportSink sink, string source, bool verify, IProgress<ImportProgress>? progress,
|
||||
CancellationToken cancellationToken, ImportSinkReport? report = null)
|
||||
{
|
||||
var results = new List<ImportItemResult>(plan.FileCount);
|
||||
@@ -232,8 +233,7 @@ public static class LocalImport
|
||||
catch (Exception ex) when (!cancellationToken.IsCancellationRequested && Stops(ex))
|
||||
{
|
||||
Log.Warning("import", $"Import into {plan.DestinationRoot} stopped", ex);
|
||||
// The server's own sentence (in the user's language) rather than the status line.
|
||||
stopped = ex is TitanoApiException api ? api.Error.Message : ex.Message;
|
||||
stopped = ImportFailures.Stop(ex, source);
|
||||
}
|
||||
return ImportOutcome.From(plan, results, verify, report, stopped);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
@@ -29,6 +30,17 @@ public static class ImportFailures
|
||||
_ => Loc.L("Import.Failed.Other"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Why the photos an import into a folder or the server never reached were not copied (<see cref="LocalImport"/>):
|
||||
/// the card left, the destination is full or refuses writing, or the server answered with its own sentence, does
|
||||
/// not answer (a timeout too) or is no longer trusted.
|
||||
/// </summary>
|
||||
public static string Stop(Exception ex, string source) => ex switch
|
||||
{
|
||||
TitanoApiException or HttpRequestException or UntrustedCertificateException or OperationCanceledException => ErrorText.ForServer(ex),
|
||||
_ => Import(ex, source),
|
||||
};
|
||||
|
||||
/// <summary>Why the card or folder could not be planned.</summary>
|
||||
public static string Plan(Exception ex, string source) => ex switch
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Protocol;
|
||||
@@ -38,7 +39,7 @@ public sealed class ServerImportSink(TitanoClient client, string stagingDirector
|
||||
ImportOutcome? outcome = null;
|
||||
try
|
||||
{
|
||||
outcome = await LocalImport.RunAsync(plan, this, verify, events.Forward(progress), cancellationToken, Report).ConfigureAwait(false);
|
||||
outcome = await LocalImport.RunAsync(plan, this, card, verify, events.Forward(progress), cancellationToken, Report).ConfigureAwait(false);
|
||||
return outcome;
|
||||
}
|
||||
finally
|
||||
@@ -69,8 +70,9 @@ public sealed class ServerImportSink(TitanoClient client, string stagingDirector
|
||||
}
|
||||
catch (TitanoApiException ex) when (IsRefusal(ex))
|
||||
{
|
||||
// The executor has no failed commit: the refusal travels in the report, which turns this result into a failure.
|
||||
Report.Rejected[file.Item.SourcePath] = ex.Error.Message;
|
||||
// The executor has no failed commit: the refusal travels in the report, which turns this result into a failure. The
|
||||
// server words its refusal in the client's language; one without words reads as the catalog's sentence.
|
||||
Report.Rejected[file.Item.SourcePath] = ErrorText.ForServer(ex);
|
||||
results.Add(new SinkCommit(null, file.Item.FileName, Duplicate: false));
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -1166,7 +1166,8 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
var progress = new Progress<ImportProgress>(ShowProgress);
|
||||
ImportOutcome outcome;
|
||||
if (choices.Destination == ImportDestinationKind.Folder)
|
||||
outcome = await Task.Run(() => LocalImport.RunAsync(plan, new FolderImportSink(choices.FolderPath!), choices.VerifyCopies, progress, cts.Token), cts.Token);
|
||||
outcome = await Task.Run(() => LocalImport.RunAsync(plan, new FolderImportSink(choices.FolderPath!), source.Title, choices.VerifyCopies, progress,
|
||||
cts.Token), cts.Token);
|
||||
else if (Services.Server.Flow is { Address: { } address, Token: { } token })
|
||||
outcome = await RunServerAsync(plan, choices, source.Title, address, token, progress, cts.Token);
|
||||
else
|
||||
@@ -1304,7 +1305,7 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
catch (DatabaseException ex)
|
||||
{
|
||||
Log.Warning("import", "The import could not be checked against the index", ex);
|
||||
return ImportOutcome.From(plan, [], verify, stopped: ex.Message);
|
||||
return ImportOutcome.From(plan, [], verify, stopped: ArchiveFailures.Cause(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ public sealed class ImportSourceUnavailableException(string root, Exception? inn
|
||||
public string Root { get; } = root;
|
||||
}
|
||||
|
||||
/// <summary>A card file is gone or has another size than when the plan was made: that photo fails, the import goes on.</summary>
|
||||
internal sealed class ImportSourceChangedException(string path) : IOException(Loc.L("Archive.Error.SourceChanged", path));
|
||||
|
||||
/// <summary>A verified copy waiting in the sink's staging folder.</summary>
|
||||
public sealed record StagedFile(PlannedItem Item, string StagedPath, string Sha256);
|
||||
|
||||
@@ -59,6 +62,8 @@ public sealed record ImportBatch(IReadOnlyList<ImportItemResult> Results, int Ne
|
||||
public sealed class ImportExecutor(ImportPlan plan, IImportSink sink)
|
||||
{
|
||||
private const int BatchSize = 32;
|
||||
private const int DiskFull = unchecked((int)0x80070070);
|
||||
private const int HandleDiskFull = unchecked((int)0x80070027);
|
||||
|
||||
/// <param name="startAt">Number of plan items already done (the last <see cref="ImportBatch.NextItem"/> recorded).</param>
|
||||
/// <param name="committed">Called after each batch; record the results, then checkpoint <see cref="ImportBatch.NextItem"/>.</param>
|
||||
@@ -119,7 +124,7 @@ public sealed class ImportExecutor(ImportPlan plan, IImportSink sink)
|
||||
try
|
||||
{
|
||||
if (new FileInfo(source) is not { Exists: true } info || info.Length != item.Size)
|
||||
throw new IOException(Loc.L("Archive.Error.SourceChanged", item.SourcePath));
|
||||
throw new ImportSourceChangedException(item.SourcePath);
|
||||
var sha = await VerifiedCopy.CopyAsync(source, target, verify, read => bytesDone += read, cancellationToken).ConfigureAwait(false);
|
||||
staged.Add(new StagedFile(item, target, sha));
|
||||
stagedSession = session;
|
||||
@@ -133,13 +138,27 @@ public sealed class ImportExecutor(ImportPlan plan, IImportSink sink)
|
||||
}
|
||||
Log.Warning("import", $"Copy of {item.SourcePath} failed", ex);
|
||||
failed++;
|
||||
results.Add(new ImportItemResult(session, item, ImportItemStatus.Failed, null, null, ex.Message));
|
||||
results.Add(new ImportItemResult(session, item, ImportItemStatus.Failed, null, null, FailureText(ex)));
|
||||
}
|
||||
}
|
||||
await FlushAsync().ConfigureAwait(false);
|
||||
return Snapshot(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Why one photo was not copied, as one localized sentence (BRIEF §0.2 rule 6): the Import screen lists it beside the
|
||||
/// photo and the import job writes it to its log. The executor's own checks say what they found; the operating
|
||||
/// system's text, technical English, goes to the application log only.
|
||||
/// </summary>
|
||||
internal static string FailureText(Exception ex) => ex switch
|
||||
{
|
||||
// Already one localized sentence each.
|
||||
ImportSourceChangedException or CopyVerificationException => ex.Message,
|
||||
IOException { HResult: DiskFull or HandleDiskFull } => Loc.L("Import.Failed.Full"),
|
||||
UnauthorizedAccessException => Loc.L("Import.Failed.PhotoAccess"),
|
||||
_ => Loc.L("Import.Failed.Photo"),
|
||||
};
|
||||
|
||||
private static void DeleteLeftover(string staged)
|
||||
{
|
||||
// Staged files are this import's own copies of card files; the originals stay on the card.
|
||||
|
||||
Reference in new issue
Block a user