merge: desktop section fixes (V-0, V-12, V-13, V-14)
Merge branch fix2/desktop-sections into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
23 files changed
+609
-75
No files matched your search
@@ -62,7 +62,10 @@ public static class CardScanner
|
||||
return files;
|
||||
}
|
||||
|
||||
/// <summary>Reads light metadata of every file; unreadable files become <paramref name="problems"/>.</summary>
|
||||
/// <summary>
|
||||
/// Reads light metadata of every file; unreadable files become <paramref name="problems"/>, each with one localized
|
||||
/// sentence (the system's text goes to the log only).
|
||||
/// </summary>
|
||||
public static IReadOnlyList<CardPhoto> ReadMetadata(string root, IReadOnlyList<CardFile> files, List<ImportProblem> problems,
|
||||
IProgress<int>? progress = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -78,7 +81,7 @@ public static class CardScanner
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Warning("import", $"Cannot read {file.RelativePath}", ex);
|
||||
problems.Add(new ImportProblem(file.RelativePath, ex.Message));
|
||||
problems.Add(new ImportProblem(file.RelativePath, ImportExecutor.FailureText(ex)));
|
||||
}
|
||||
progress?.Report(i + 1);
|
||||
}
|
||||
|
||||
@@ -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