diff --git a/i18n/en/Import.resx b/i18n/en/Import.resx
index 594867fa..4ded1106 100644
--- a/i18n/en/Import.resx
+++ b/i18n/en/Import.resx
@@ -109,6 +109,8 @@
A photo or its archive copy could not be read.long
The destination is full.long
The import stopped before the end.long
+ The photo could not be read or copied.long
+ Titano was denied access to the photo or its copy.long
Retry
The server did not accept the photos.long
{0} is no longer available.long
diff --git a/i18n/it/Import.it.resx b/i18n/it/Import.it.resx
index d7f703a7..aa9a3724 100644
--- a/i18n/it/Import.it.resx
+++ b/i18n/it/Import.it.resx
@@ -107,6 +107,8 @@
Impossibile leggere una foto o la sua copia nell'archivio.
La destinazione è piena.
L'importazione si è interrotta prima della fine.
+ Impossibile leggere o copiare la foto.
+ A Titano è stato negato l'accesso alla foto o alla sua copia.
Riprova
Il server non ha accettato le foto.
{0} non è più disponibile.
diff --git a/src/Titano.App/Import/ImportDestinations.cs b/src/Titano.App/Import/ImportDestinations.cs
index 426541ef..89136bd1 100644
--- a/src/Titano.App/Import/ImportDestinations.cs
+++ b/src/Titano.App/Import/ImportDestinations.cs
@@ -211,7 +211,8 @@ public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IRea
///
public static class LocalImport
{
- public static async Task RunAsync(ImportPlan plan, IImportSink sink, bool verify, IProgress? progress,
+ /// The card or folder as the Devices list names it (a card that leaves is named in each failure).
+ public static async Task RunAsync(ImportPlan plan, IImportSink sink, string source, bool verify, IProgress? progress,
CancellationToken cancellationToken, ImportSinkReport? report = null)
{
var results = new List(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);
}
diff --git a/src/Titano.App/Import/ImportFailures.cs b/src/Titano.App/Import/ImportFailures.cs
index e648a40a..b1308733 100644
--- a/src/Titano.App/Import/ImportFailures.cs
+++ b/src/Titano.App/Import/ImportFailures.cs
@@ -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"),
};
+ ///
+ /// Why the photos an import into a folder or the server never reached were not copied ():
+ /// 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.
+ ///
+ public static string Stop(Exception ex, string source) => ex switch
+ {
+ TitanoApiException or HttpRequestException or UntrustedCertificateException or OperationCanceledException => ErrorText.ForServer(ex),
+ _ => Import(ex, source),
+ };
+
/// Why the card or folder could not be planned.
public static string Plan(Exception ex, string source) => ex switch
{
diff --git a/src/Titano.App/Import/ServerImportSink.cs b/src/Titano.App/Import/ServerImportSink.cs
index f05584fa..311c34fe 100644
--- a/src/Titano.App/Import/ServerImportSink.cs
+++ b/src/Titano.App/Import/ServerImportSink.cs
@@ -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
diff --git a/src/Titano.App/Sections/ImportViewModel.cs b/src/Titano.App/Sections/ImportViewModel.cs
index 96d76ba1..fcc45e58 100644
--- a/src/Titano.App/Sections/ImportViewModel.cs
+++ b/src/Titano.App/Sections/ImportViewModel.cs
@@ -1166,7 +1166,8 @@ public sealed class ImportViewModel : SectionViewModel
var progress = new Progress(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));
}
}
diff --git a/src/Titano.Core/Import/ImportExecutor.cs b/src/Titano.Core/Import/ImportExecutor.cs
index 3a8c0728..5a7f166e 100644
--- a/src/Titano.Core/Import/ImportExecutor.cs
+++ b/src/Titano.Core/Import/ImportExecutor.cs
@@ -10,6 +10,9 @@ public sealed class ImportSourceUnavailableException(string root, Exception? inn
public string Root { get; } = root;
}
+/// A card file is gone or has another size than when the plan was made: that photo fails, the import goes on.
+internal sealed class ImportSourceChangedException(string path) : IOException(Loc.L("Archive.Error.SourceChanged", path));
+
/// A verified copy waiting in the sink's staging folder.
public sealed record StagedFile(PlannedItem Item, string StagedPath, string Sha256);
@@ -59,6 +62,8 @@ public sealed record ImportBatch(IReadOnlyList 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);
/// Number of plan items already done (the last recorded).
/// Called after each batch; record the results, then checkpoint .
@@ -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);
}
+ ///
+ /// 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.
+ ///
+ 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.
diff --git a/tests/Titano.App.Tests/Import/ImportFailuresTests.cs b/tests/Titano.App.Tests/Import/ImportFailuresTests.cs
index 79d47c92..7821fad2 100644
--- a/tests/Titano.App.Tests/Import/ImportFailuresTests.cs
+++ b/tests/Titano.App.Tests/Import/ImportFailuresTests.cs
@@ -31,6 +31,22 @@ public sealed class ImportFailuresTests
Assert.Equal("The import stopped before the end.", ImportFailures.Import(new InvalidDataException("Bad sidecar. Second sentence."), Card));
}
+ [Test]
+ public void TheCopiesAStoppedImportNeverReachedSayWhyInOneSentence()
+ {
+ const string Card = "EOS R5 · card A";
+ Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Stop(new ImportSourceUnavailableException(@"E:\"), Card));
+ Assert.Equal("The destination is full.", ImportFailures.Stop(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070)), Card));
+ Assert.Equal("Titano may not write to the destination.", ImportFailures.Stop(new UnauthorizedAccessException(@"Access to D:\Shoots is denied."), Card));
+ Assert.Equal("The import stopped before the end.", ImportFailures.Stop(new IOException("The specified network name is no longer available."), Card));
+ // The server's own sentence, else why it could not be asked.
+ Assert.Equal("Sign in again",
+ ImportFailures.Stop(new TitanoApiException(HttpStatusCode.Unauthorized, new ApiError("unauthorized", "Sign in again", null)), Card));
+ Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new HttpRequestException("An error occurred while sending the request."), Card));
+ Assert.Equal(Loc.L("Server.Error.Unreachable"), ImportFailures.Stop(new TaskCanceledException("The operation was canceled."), Card));
+ Assert.Equal(Loc.L("Server.Error.Untrusted"), ImportFailures.Stop(new UntrustedCertificateException("AB:CD"), Card));
+ }
+
[Test]
public void APlanningFailureNamesTheSource()
{
diff --git a/tests/Titano.App.Tests/Import/ImportFlowTests.cs b/tests/Titano.App.Tests/Import/ImportFlowTests.cs
index a8289519..f4ff7778 100644
--- a/tests/Titano.App.Tests/Import/ImportFlowTests.cs
+++ b/tests/Titano.App.Tests/Import/ImportFlowTests.cs
@@ -1,5 +1,6 @@
using System.Globalization;
using System.IO;
+using System.Net.Http;
using Titano.App.Import;
using Titano.Core.Import;
using Titano.Core.Localization;
@@ -111,7 +112,7 @@ public sealed class ImportFlowTests(TestContext context)
Assert.Equal(16, plan.CopyCount);
var reports = new List();
- var outcome = await LocalImport.RunAsync(plan, new FolderImportSink(target), verify: true, new Progress(reports), context.Cancellation);
+ var outcome = await LocalImport.RunAsync(plan, new FolderImportSink(target), "EOS R5 · card A", verify: true, new Progress(reports), context.Cancellation);
Assert.Equal(16, outcome.Copied);
Assert.True(outcome.IsComplete);
Assert.True(outcome.Verified);
@@ -120,7 +121,7 @@ public sealed class ImportFlowTests(TestContext context)
Assert.FileExists(Path.Combine(target, folder, name));
var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation),
- new FolderImportSink(target), verify: true, null, context.Cancellation);
+ new FolderImportSink(target), "EOS R5 · card A", verify: true, null, context.Cancellation);
Assert.Equal(0, again.Copied);
Assert.Equal(16, again.Duplicates);
Assert.False(new CardActions(ImportDestinationKind.Folder, false, true, true, outcome, null, null).CanCheck);
@@ -164,6 +165,21 @@ public sealed class ImportFlowTests(TestContext context)
outcome.Failures);
}
+ [Test]
+ public async Task ARunTheServerStopsListsEveryPhotoLeftWithASentenceNotTheExceptionText()
+ {
+ Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ var card = Card(context.CreateTempDirectory("card"), 8, Start);
+ var staging = context.CreateTempDirectory("staging");
+ var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null,
+ context.Cancellation);
+
+ var outcome = await LocalImport.RunAsync(plan, new UnreachableSink(staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
+ Assert.Equal(0, outcome.Imported);
+ Assert.Equal(8, outcome.Failures.Count);
+ Assert.True(outcome.Failures.All(f => f.Message == Loc.L("Server.Error.Unreachable")), "the stop reason is the catalog's, never the exception's text");
+ }
+
private async Task WaitDoneAsync(TitanoDatabase db, Guid jobId)
{
var until = DateTime.UtcNow.AddSeconds(60);
@@ -177,6 +193,15 @@ public sealed class ImportFlowTests(TestContext context)
Assert.Fail("The import job did not finish");
}
+ /// A server destination whose connection is gone: every commit fails as the HTTP stack reports it.
+ private sealed class UnreachableSink(string staging) : IImportSink
+ {
+ public string StagingDirectory { get; } = staging;
+
+ public Task> CommitAsync(PlannedSession session, IReadOnlyList files, CancellationToken cancellationToken) =>
+ throw new HttpRequestException("An error occurred while sending the request.");
+ }
+
/// Collects reports synchronously (System.Progress posts to the thread pool).
private sealed class Progress(List into) : IProgress
{
diff --git a/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs b/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs
index b957ad21..6fc74a94 100644
--- a/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs
+++ b/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs
@@ -27,7 +27,7 @@ public sealed class ServerImportSinkTests(TestContext context)
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
plan = plan with { Sessions = [plan.Sessions[0] with { Title = "Harbour sunset" }, .. plan.Sessions.Skip(1)] };
- var outcome = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation);
+ var outcome = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
Assert.Equal(16, outcome.Copied);
Assert.True(outcome.IsComplete);
@@ -55,10 +55,10 @@ public sealed class ServerImportSinkTests(TestContext context)
using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" };
var destination = new UnindexedDestination(ImportDestinationKind.Server, staging);
var plan = await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
- await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation);
+ await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
var chunks = server.ChunkCount;
- var again = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation);
+ var again = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), "EOS R5 · card A", verify: true, null, context.Cancellation);
Assert.Equal(0, again.Copied);
Assert.Equal(8, again.Duplicates);
Assert.Equal(chunks, server.ChunkCount);
@@ -74,7 +74,7 @@ public sealed class ServerImportSinkTests(TestContext context)
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
var sink = new ServerImportSink(client, staging);
- var outcome = await LocalImport.RunAsync(plan, sink, true, null, context.Cancellation, sink.Report);
+ var outcome = await LocalImport.RunAsync(plan, sink, "EOS R5 · card A", true, null, context.Cancellation, sink.Report);
Assert.Equal(7, outcome.Copied);
Assert.Equal(7, server.Committed.Count);
Assert.Equal(new ImportFailure("DCIM/100CANON/IMG_0003.JPG", "Hash mismatch"), outcome.Failures.Single());
@@ -91,7 +91,7 @@ public sealed class ServerImportSinkTests(TestContext context)
var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation);
var sink = new ServerImportSink(client, staging);
- var outcome = await LocalImport.RunAsync(plan, sink, true, null, context.Cancellation, sink.Report);
+ var outcome = await LocalImport.RunAsync(plan, sink, "EOS R5 · card A", true, null, context.Cancellation, sink.Report);
Assert.Equal(3, outcome.Copied, "the uploads the server committed before the sign-in was lost");
Assert.Equal(5, outcome.Failures.Count);
Assert.Equal("Sign in again", outcome.Failures[0].Message, "the server's sentence");
diff --git a/tests/Titano.Core.Tests/Import/ImportExecutorTests.cs b/tests/Titano.Core.Tests/Import/ImportExecutorTests.cs
index 8fdb8f4d..1d1c2d39 100644
--- a/tests/Titano.Core.Tests/Import/ImportExecutorTests.cs
+++ b/tests/Titano.Core.Tests/Import/ImportExecutorTests.cs
@@ -1,5 +1,6 @@
using Titano.Core.Archiving;
using Titano.Core.Import;
+using Titano.Core.Localization;
using Titano.Core.Tests.Archiving;
using Titano.Testing;
using static Titano.Core.Tests.Import.ImportTestKit;
@@ -141,6 +142,41 @@ public sealed class ImportExecutorTests(TestContext context)
Assert.Equal(19, final.Copied);
Assert.Equal(1, final.Failed);
Assert.Equal(plan.Sessions[0].Items[5].SourcePath, failed.Single().Item.SourcePath);
+ Assert.Equal(Loc.L("Archive.Error.SourceChanged", plan.Sessions[0].Items[5].SourcePath), failed.Single().Error);
+ }
+
+ [Test]
+ public async Task ACopyTheSystemRefusesFailsAloneWithACatalogSentence()
+ {
+ var card = Card(10);
+ var destination = context.CreateTempDirectory("dest");
+ var plan = await PlanAsync(card, destination);
+ var sink = new FolderImportSink(destination);
+ // A folder squats the staging name of the fourth copy: creating that copy fails with the system's own text.
+ var item = plan.Sessions[0].Items[3];
+ Directory.CreateDirectory(Path.Combine(sink.StagingDirectory, $"{plan.Id:N}-{3:D6}{Path.GetExtension(item.FileName)}"));
+ var failed = new List();
+ var final = await RunAsync(plan, sink, committed: b =>
+ {
+ failed.AddRange(b.Results.Where(r => r.Status == ImportItemStatus.Failed));
+ return ValueTask.CompletedTask;
+ });
+ Assert.Equal(9, final.Copied);
+ Assert.Equal(item.SourcePath, failed.Single().Item.SourcePath);
+ Assert.Contains(failed.Single().Error, new[] { Loc.L("Import.Failed.Photo"), Loc.L("Import.Failed.PhotoAccess") });
+ }
+
+ [Test]
+ public void AFailedCopySaysWhyInOneLocalizedSentence()
+ {
+ Assert.Equal(Loc.L("Import.Failed.Full"), ImportExecutor.FailureText(new IOException("There is not enough space on the disk.", unchecked((int)0x80070070))));
+ Assert.Equal(Loc.L("Import.Failed.Full"), ImportExecutor.FailureText(new IOException("The disk is full.", unchecked((int)0x80070027))));
+ Assert.Equal(Loc.L("Import.Failed.PhotoAccess"), ImportExecutor.FailureText(new UnauthorizedAccessException(@"Access to the path 'E:\DCIM\IMG_0001.CR3' is denied.")));
+ Assert.Equal(Loc.L("Import.Failed.Photo"), ImportExecutor.FailureText(new IOException("The semaphore timeout period has expired.")));
+ Assert.Equal(Loc.L("Import.Failed.Photo"), ImportExecutor.FailureText(new FileNotFoundException(@"Could not find file 'E:\DCIM\IMG_0001.CR3'.")));
+ // The executor's own checks are one sentence each already.
+ Assert.Equal(Loc.L("Archive.Error.CopyMismatch", "IMG_0001.CR3"), ImportExecutor.FailureText(new CopyVerificationException("/staging/IMG_0001.CR3")));
+ Assert.Equal(Loc.L("Archive.Error.SourceChanged", "DCIM/IMG_0001.CR3"), ImportExecutor.FailureText(new ImportSourceChangedException("DCIM/IMG_0001.CR3")));
}
[Test]