fix(app): import gates, partial results and plan editing after review
- a card that leaves needs a new check; formatting re-lists the card and refuses one that changed since its check; files that are not photos are named in the format confirmation - an import never stays stuck in Running; Retry never resumes an older job - server imports list refused files and keep what was uploaded when stopped - the archive result matches each copy to its job's record and shows the job's own error per file - refreshing devices keeps typed titles and choices; titles lock while copying - three destination names, merge and split of sessions, camera profiles shared by the cards of a camera, photo counts and a new-card toast - disabled controls say why; keyboard focus follows the nickname field and Show plan (Esc closes it); label column fits longer languages - capture states for insertion, running, failed and a new card Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
27 files changed
+1286
-285
No files matched your search
@@ -1,6 +1,12 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Protocol.Client;
|
||||
|
||||
namespace Titano.App.Import;
|
||||
|
||||
@@ -67,6 +73,29 @@ public sealed class UnindexedDestination(ImportDestinationKind kind, string root
|
||||
/// <summary>A failed photo of an import: where it is on the card and why.</summary>
|
||||
public sealed record ImportFailure(string SourcePath, string Message);
|
||||
|
||||
/// <summary>Whether a planned copy reached the archive after an archive import job.</summary>
|
||||
public enum CommitCheck
|
||||
{
|
||||
/// <summary>No frame of the archive is this photo's copy.</summary>
|
||||
Missing,
|
||||
|
||||
/// <summary>The job committed a new frame for the photo.</summary>
|
||||
Copied,
|
||||
|
||||
/// <summary>The job found the same content already at the destination and kept that frame.</summary>
|
||||
AlreadyThere,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What a destination did per card file beyond the executor's commit results (server imports): the files it committed,
|
||||
/// also those of a batch an abort interrupted, and the files it refused with the reason.
|
||||
/// </summary>
|
||||
public sealed class ImportSinkReport
|
||||
{
|
||||
public Dictionary<string, SinkCommit> Committed { get; } = new(StringComparer.Ordinal);
|
||||
public Dictionary<string, string> Rejected { get; } = new(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>What an import did (BRIEF §12.4 verification result).</summary>
|
||||
/// <param name="Copied">Copied and committed (verified by read-back when <paramref name="Verified"/>).</param>
|
||||
/// <param name="Duplicates">Copied, but the destination already held the same content.</param>
|
||||
@@ -78,14 +107,30 @@ public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IRea
|
||||
/// <summary>Photos the destination now holds a verified copy of.</summary>
|
||||
public int Imported => Copied + Duplicates;
|
||||
|
||||
/// <summary>Totals of an executor run (folder or server destination).</summary>
|
||||
public static ImportOutcome From(IEnumerable<ImportItemResult> results, bool verified)
|
||||
/// <summary>
|
||||
/// Totals of an executor run (folder or server destination): the executor's per-file results, corrected by what the
|
||||
/// sink reported (refused files fail, files committed in a batch an abort interrupted count); after an abort
|
||||
/// (<paramref name="stopped"/>) every copy not reached fails with that reason.
|
||||
/// </summary>
|
||||
public static ImportOutcome From(ImportPlan plan, IEnumerable<ImportItemResult> results, bool verified, ImportSinkReport? report = null,
|
||||
string? stopped = null)
|
||||
{
|
||||
var byPath = new Dictionary<string, ImportItemResult>(StringComparer.Ordinal);
|
||||
foreach (var r in results) byPath[r.Item.SourcePath] = r;
|
||||
int copied = 0, duplicates = 0, skipped = 0;
|
||||
var failures = new List<ImportFailure>();
|
||||
foreach (var r in results)
|
||||
foreach (var item in plan.Items)
|
||||
{
|
||||
switch (r.Status)
|
||||
if (report?.Rejected.TryGetValue(item.SourcePath, out var refused) == true)
|
||||
{
|
||||
failures.Add(new ImportFailure(item.SourcePath, refused));
|
||||
continue;
|
||||
}
|
||||
var status = byPath.TryGetValue(item.SourcePath, out var result) ? result.Status
|
||||
: report?.Committed.TryGetValue(item.SourcePath, out var commit) == true ? commit.Duplicate ? ImportItemStatus.Duplicate : ImportItemStatus.Copied
|
||||
: item.Action != ImportAction.Copy ? ImportItemStatus.Skipped
|
||||
: ImportItemStatus.Failed;
|
||||
switch (status)
|
||||
{
|
||||
case ImportItemStatus.Copied:
|
||||
copied++;
|
||||
@@ -97,7 +142,7 @@ public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IRea
|
||||
skipped++;
|
||||
break;
|
||||
default:
|
||||
failures.Add(new ImportFailure(r.Item.SourcePath, r.Error ?? string.Empty));
|
||||
failures.Add(new ImportFailure(item.SourcePath, result?.Error ?? stopped ?? Loc.L("Import.Result.NotCommitted")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -105,13 +150,14 @@ public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IRea
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// After an archive import job: every planned copy must now be a frame of the archive (found by size and capture
|
||||
/// time, the planner's own duplicate key); the copy was hashed and read back while the job ran.
|
||||
/// After an archive import job: each planned copy is matched to its own committed frame (<paramref name="check"/>);
|
||||
/// a copy that did not arrive shows the job's own error for that file (<paramref name="errors"/>, from its log) or
|
||||
/// that it was not committed. The copies were hashed and read back while the job ran.
|
||||
/// </summary>
|
||||
public static async Task<ImportOutcome> CheckAsync(ImportPlan plan, bool verified, Func<PlannedItem, CancellationToken, Task<bool>> isInArchive,
|
||||
CancellationToken cancellationToken)
|
||||
public static async Task<ImportOutcome> CheckAsync(ImportPlan plan, bool verified, Func<PlannedItem, CancellationToken, Task<CommitCheck>> check,
|
||||
IReadOnlyDictionary<string, string> errors, CancellationToken cancellationToken)
|
||||
{
|
||||
int copied = 0, skipped = 0;
|
||||
int copied = 0, duplicates = 0, skipped = 0;
|
||||
var failures = new List<ImportFailure>();
|
||||
foreach (var item in plan.Items)
|
||||
{
|
||||
@@ -120,33 +166,80 @@ public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IRea
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
if (await isInArchive(item, cancellationToken).ConfigureAwait(false)) copied++;
|
||||
else failures.Add(new ImportFailure(item.SourcePath, Core.Localization.Loc.L("Import.Result.NotCommitted")));
|
||||
switch (await check(item, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
case CommitCheck.Copied:
|
||||
copied++;
|
||||
break;
|
||||
case CommitCheck.AlreadyThere:
|
||||
duplicates++;
|
||||
break;
|
||||
default:
|
||||
failures.Add(new ImportFailure(item.SourcePath,
|
||||
errors.TryGetValue(item.SourcePath, out var error) ? error : Loc.L("Import.Result.NotCommitted")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new ImportOutcome(copied, 0, skipped, failures, verified);
|
||||
return new ImportOutcome(copied, duplicates, skipped, failures, verified);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The per-file errors an import job wrote to its log ("Not copied: path (error)", in the language it ran in), by card
|
||||
/// path. The log keeps its last lines only, so older errors fall back to "not committed".
|
||||
/// </summary>
|
||||
public static IReadOnlyDictionary<string, string> JobErrors(string? logTail)
|
||||
{
|
||||
var errors = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
if (string.IsNullOrEmpty(logTail)) return errors;
|
||||
var line = Regex.Escape(Loc.L("Archive.Log.ImportFailed", "\u0001", "\u0002"))
|
||||
.Replace("\u0001", "(?<path>.+?)", StringComparison.Ordinal)
|
||||
.Replace("\u0002", "(?<error>.*)", StringComparison.Ordinal);
|
||||
var pattern = new Regex("^(?:\\S+ )?" + line + "$", RegexOptions.CultureInvariant);
|
||||
foreach (var entry in logTail.Split('\n'))
|
||||
{
|
||||
if (pattern.Match(entry.TrimEnd('\r')) is { Success: true } match) errors[match.Groups["path"].Value] = match.Groups["error"].Value;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a confirmed plan into a folder or the server on this PC (no job handler exists for those destinations): copies
|
||||
/// with hashing and read-back, commits each batch to the sink and collects the per-file results.
|
||||
/// with hashing and read-back, commits each batch to the sink and collects the per-file results. A card that leaves or
|
||||
/// a destination that fails as a whole (disk, connection, sign-in) stops the run; what was done until then is kept in
|
||||
/// the outcome and every copy not reached fails with the reason.
|
||||
/// </summary>
|
||||
public static class LocalImport
|
||||
{
|
||||
public static async Task<ImportOutcome> RunAsync(ImportPlan plan, IImportSink sink, bool verify, IProgress<ImportProgress>? progress,
|
||||
CancellationToken cancellationToken)
|
||||
CancellationToken cancellationToken, ImportSinkReport? report = null)
|
||||
{
|
||||
var results = new List<ImportItemResult>(plan.FileCount);
|
||||
await new ImportExecutor(plan, sink).RunAsync(0, verify, batch =>
|
||||
string? stopped = null;
|
||||
try
|
||||
{
|
||||
results.AddRange(batch.Results);
|
||||
progress?.Report(batch.Progress);
|
||||
return ValueTask.CompletedTask;
|
||||
}, p =>
|
||||
await new ImportExecutor(plan, sink).RunAsync(0, verify, batch =>
|
||||
{
|
||||
results.AddRange(batch.Results);
|
||||
progress?.Report(batch.Progress);
|
||||
return ValueTask.CompletedTask;
|
||||
}, p =>
|
||||
{
|
||||
progress?.Report(p);
|
||||
return ValueTask.CompletedTask;
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (!cancellationToken.IsCancellationRequested && Stops(ex))
|
||||
{
|
||||
progress?.Report(p);
|
||||
return ValueTask.CompletedTask;
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
return ImportOutcome.From(results, verify);
|
||||
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;
|
||||
}
|
||||
return ImportOutcome.From(plan, results, verify, report, stopped);
|
||||
}
|
||||
|
||||
/// <summary>The card left, or the destination as a whole failed: its disk, the connection, the sign-in or the server (a timeout too).</summary>
|
||||
private static bool Stops(Exception ex) =>
|
||||
ex is IOException or UnauthorizedAccessException or HttpRequestException or TitanoApiException or UntrustedCertificateException
|
||||
or InvalidOperationException or OperationCanceledException;
|
||||
}
|
||||
Reference in new issue
Block a user