Repository navigation
Expand file tree
/
Copy pathBatchConversion.cs
More file actions
723 lines (636 loc) · 26.6 KB
/
Copy pathBatchConversion.cs
File metadata and controls
723 lines (636 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace XISOSharp.Cli;
/// <summary>
/// Parsed <c>--batch</c> flags shared by the container verbs
/// (<c>compress</c>, <c>decompress</c>, <c>convert</c> and <c>split</c>).
/// </summary>
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global",
Justification = "AssumeYes/AssumeNo are set by the CLI parsers and read by BatchConversion.")]
internal sealed class BatchOptions
{
/// <summary>Directory scanned for sources; <c>null</c> means single-source mode.</summary>
internal string? Directory { get; set; }
/// <summary>Recurse into subdirectories.</summary>
internal bool Recursive { get; set; }
/// <summary>Skip a source when all of its expected outputs already exist.</summary>
internal bool SkipExisting { get; set; }
/// <summary>Keep converting after a per-file failure and report the failures at the end.</summary>
internal bool ContinueOnError { get; set; }
/// <summary>
/// Delete each source image after its conversion succeeds. Requires
/// <c>-y</c>/<c>--yes</c>; a split set deletes every part.
/// </summary>
internal bool DeleteSource { get; set; }
/// <summary>Maximum conversions run in parallel (default 1).</summary>
internal int Jobs { get; set; } = 1;
/// <summary>True when <c>--jobs</c> appeared (used to reject it outside batch mode).</summary>
internal bool JobsSpecified { get; set; }
/// <summary>Output-name template; <c>null</c> uses the per-format default.</summary>
internal string? OutputName { get; set; }
/// <summary>Overwrite existing outputs without prompting.</summary>
internal bool AssumeYes { get; set; }
/// <summary>Never overwrite existing outputs.</summary>
internal bool AssumeNo { get; set; }
}
/// <summary>
/// Shared batch conversion support for the standalone container verbs:
/// source discovery, output-name templates, collision guards, per-file
/// overwrite policy, optional parallelism and the closing summary.
/// </summary>
internal static class BatchConversion
{
/// <summary>Maximum accepted <c>--jobs</c> value.</summary>
internal const int MaxJobs = 64;
/// <summary>
/// Consumes one batch-related argument. Returns <c>true</c> when
/// <paramref name="args"/>[<paramref name="i"/>] was a batch flag (and
/// advances <paramref name="i"/> past its value); <paramref name="error"/>
/// is set when the flag's value is missing or invalid.
/// </summary>
internal static bool TryConsume(string[] args, ref int i, BatchOptions options, out string? error)
{
error = null;
string a = args[i];
if (string.Equals(a, "--batch", StringComparison.OrdinalIgnoreCase))
{
if (i + 1 >= args.Length)
{
error = "--batch requires a directory";
return true;
}
options.Directory = args[++i];
return true;
}
if (string.Equals(a, "--batch-recursive", StringComparison.OrdinalIgnoreCase))
{
options.Recursive = true;
return true;
}
if (string.Equals(a, "--skip-existing", StringComparison.OrdinalIgnoreCase))
{
options.SkipExisting = true;
return true;
}
if (string.Equals(a, "--continue-on-error", StringComparison.OrdinalIgnoreCase))
{
options.ContinueOnError = true;
return true;
}
if (string.Equals(a, "--delete-source", StringComparison.OrdinalIgnoreCase))
{
options.DeleteSource = true;
return true;
}
if (string.Equals(a, "--jobs", StringComparison.OrdinalIgnoreCase))
{
if (i + 1 >= args.Length ||
!int.TryParse(args[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out int jobs) ||
jobs < 1 || jobs > MaxJobs)
{
error = $"--jobs requires an integer 1..{MaxJobs}";
return true;
}
options.Jobs = jobs;
options.JobsSpecified = true;
i++;
return true;
}
if (string.Equals(a, "--output-name", StringComparison.OrdinalIgnoreCase))
{
if (i + 1 >= args.Length)
{
error = "--output-name requires a template";
return true;
}
options.OutputName = args[++i];
return true;
}
return false;
}
/// <summary>
/// Validates batch-only flags after parsing. Returns the error line, or
/// <c>null</c> when the combination is valid.
/// </summary>
/// <param name="options">Parsed batch flags.</param>
/// <param name="allowJobsWithoutBatch">
/// <c>true</c> for <c>compress</c>, where <c>--jobs</c> also selects the
/// per-sector CISO/CCI compression worker count in single-file mode.
/// </param>
internal static string? Validate(BatchOptions options, bool allowJobsWithoutBatch = false)
{
bool batch = options.Directory != null;
if (!batch)
{
if (options.Recursive)
return "--batch-recursive requires --batch <directory>";
if (options.SkipExisting)
return "--skip-existing requires --batch <directory>";
if (options.ContinueOnError)
return "--continue-on-error requires --batch <directory>";
if (options.DeleteSource)
return "--delete-source requires --batch <directory>";
if (options.JobsSpecified && !allowJobsWithoutBatch)
return "--jobs requires --batch <directory>";
if (options.OutputName != null)
return "--output-name requires --batch <directory>";
return null;
}
if (options.OutputName != null)
{
string? templateError = ValidateTemplate(options.OutputName);
if (templateError != null)
return templateError;
}
return null;
}
/// <summary>
/// Returns the first unknown <c>{token}</c> in an output-name template, or
/// <c>null</c> when every token is one of <c>{name}</c>, <c>{ext}</c> or
/// <c>{format}</c>.
/// </summary>
internal static string? ValidateTemplate(string template)
{
if (string.IsNullOrWhiteSpace(template))
return "--output-name requires a non-empty template";
for (int i = 0; i < template.Length; i++)
{
if (template[i] != '{')
continue;
int end = template.IndexOf('}', i + 1);
if (end < 0)
return "--output-name has an unterminated '{'";
string token = template[(i + 1)..end];
if (!token.Equals("name", StringComparison.OrdinalIgnoreCase) &&
!token.Equals("ext", StringComparison.OrdinalIgnoreCase) &&
!token.Equals("format", StringComparison.OrdinalIgnoreCase))
{
return $"--output-name has unknown placeholder '{{{token}}}' " +
"(supported: {name}, {ext}, {format})";
}
i = end;
}
return null;
}
/// <summary>
/// Expands <c>{name}</c> (source stem with a <c>.1</c> split marker and
/// container extension stripped), <c>{ext}</c> (source extension without
/// the dot) and <c>{format}</c> (output extension).
/// </summary>
internal static string ExpandTemplate(string template, string sourcePath, string format)
{
string extension = Path.GetExtension(sourcePath).TrimStart('.');
return template
.Replace("{name}", BaseName(sourcePath), StringComparison.OrdinalIgnoreCase)
.Replace("{ext}", extension, StringComparison.OrdinalIgnoreCase)
.Replace("{format}", format, StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Resolves the output path for one batch source. Relative templates are
/// resolved against the source directory; an output without an extension
/// gets <c>.<paramref name="format"/></c> when
/// <paramref name="appendExtension"/> is set.
/// </summary>
internal static string OutputPath(string sourcePath, string? template, string format, bool appendExtension)
{
string directory = Path.GetDirectoryName(sourcePath) ?? string.Empty;
string name;
if (template is null)
{
name = BaseName(sourcePath);
if (appendExtension)
name += "." + format;
}
else
{
name = ExpandTemplate(template, sourcePath, format);
if (appendExtension && string.IsNullOrEmpty(Path.GetExtension(name)))
name += "." + format;
}
string combined = Path.IsPathRooted(name) ? name : Path.Combine(directory, name);
return Path.GetFullPath(combined);
}
/// <summary>
/// Source stem with the image extension removed and, for split-capable
/// ISO/CISO/CCI names, a trailing <c>.1</c> split marker: <c>game.iso</c>
/// <c>game</c>, <c>game.1.cso</c> <c>game</c>, <c>game.1.cci</c>
/// <c>game</c>. A numbered name in another format (<c>archive.1.zar</c>)
/// keeps its number.
/// </summary>
internal static string BaseName(string path)
{
string file = Path.GetFileName(path);
string extension = Path.GetExtension(file);
string stem = extension.Length > 0 ? file[..^extension.Length] : file;
bool splitCapable = extension.Equals(".iso", StringComparison.OrdinalIgnoreCase) ||
extension.Equals(".cso", StringComparison.OrdinalIgnoreCase) ||
extension.Equals(".cci", StringComparison.OrdinalIgnoreCase);
if (splitCapable && stem.EndsWith(".1", StringComparison.Ordinal))
stem = stem[..^2];
return stem;
}
/// <summary>
/// Enumerates sources matching <paramref name="extensions"/> (case-insensitive
/// on every platform), sorted for deterministic runs. When
/// <paramref name="includeFirstPart"/> is set, the first part of a split
/// set (<c>game.1.iso</c>) is kept and later parts are dropped; otherwise
/// every numbered part is dropped.
/// </summary>
internal static List<string> EnumerateSources(
string directory,
bool recursive,
bool includeFirstPart,
params string[] extensions)
{
if (!Directory.Exists(directory))
throw new DirectoryNotFoundException($"batch directory not found: {directory}");
EnumerationOptions enumeration = new()
{
MatchCasing = MatchCasing.CaseInsensitive,
RecurseSubdirectories = recursive,
AttributesToSkip = FileAttributes.None
};
List<string> sources = [];
foreach (string path in Directory.EnumerateFiles(directory, "*", enumeration))
{
string extension = Path.GetExtension(path);
if (!extensions.Any(e => extension.Equals(e, StringComparison.OrdinalIgnoreCase)))
continue;
int part = GetSplitPart(path);
if (part > 0 && (!includeFirstPart || part != 1))
continue;
sources.Add(Path.GetFullPath(path));
}
sources.Sort(StringComparer.OrdinalIgnoreCase);
return sources;
}
/// <summary>
/// Returns the numeric split-part index of an ISO/CISO/CCI image name
/// (<c>game.2.iso</c> 2), or 0 when the name is not a numbered part.
/// Only small indexes (1..999) count, so names such as
/// <c>game.2004.iso</c> stay ordinary images; other extensions (notably
/// <c>.zar</c>) are never treated as split parts.
/// </summary>
internal static int GetSplitPart(string path)
{
string extension = Path.GetExtension(path);
if (!extension.Equals(".iso", StringComparison.OrdinalIgnoreCase) &&
!extension.Equals(".cso", StringComparison.OrdinalIgnoreCase) &&
!extension.Equals(".cci", StringComparison.OrdinalIgnoreCase))
{
// Only ISO/CISO/CCI sets are numbered parts; `archive.1.zar` is a
// perfectly ordinary ZArchive name.
return 0;
}
string stem = Path.GetFileNameWithoutExtension(path);
int dot = stem.LastIndexOf('.');
if (dot <= 0 || dot == stem.Length - 1)
return 0;
if (!int.TryParse(stem.AsSpan(dot + 1), NumberStyles.None, CultureInfo.InvariantCulture, out int part) ||
part is < 1 or > 999)
{
return 0;
}
return part;
}
/// <summary>
/// Returns every file that belongs to a batch source. For a split set
/// (<c>game.1.iso</c>, <c>game.1.cso</c>, <c>game.1.cci</c>) this is every
/// contiguous part starting at 1; otherwise it is just the source file.
/// Used by <c>--delete-source</c> so a completed conversion removes the
/// whole set, not only its first part.
/// </summary>
internal static IReadOnlyList<string> SourceFiles(string source)
{
string full = Path.GetFullPath(source);
string extension = Path.GetExtension(full);
if (GetSplitPart(full) <= 0)
return [full];
string stem = Path.GetFileNameWithoutExtension(full);
int dot = stem.LastIndexOf('.');
if (dot <= 0)
return [full];
string baseName = stem[..dot];
string directory = Path.GetDirectoryName(full) ?? string.Empty;
List<string> files = [];
for (int part = 1; part <= 999; part++)
{
string candidate = Path.Combine(
directory,
string.Concat(baseName, ".", part.ToString(CultureInfo.InvariantCulture), extension));
if (!File.Exists(candidate))
break;
files.Add(candidate);
}
return files.Count > 0 ? files : [full];
}
/// <summary>
/// Computes the part paths a split of <paramref name="isoPath"/> would
/// write. Returns an empty list when the source cannot be probed; the
/// split call itself then reports the real error.
/// </summary>
internal static IReadOnlyList<string> SplitTargets(string isoPath, string splitBase, long partSize, bool halves)
{
try
{
if (!File.Exists(isoPath))
return [];
long length = new FileInfo(isoPath).Length;
if (length <= 0)
return [];
long chunk;
if (halves)
{
long cut = (((length + 1) / 2) + Constants.SectorSize - 1) / Constants.SectorSize *
Constants.SectorSize;
chunk = cut <= 0 || cut >= length ? length : cut;
}
else
{
chunk = (partSize / Constants.SectorSize) * Constants.SectorSize;
if (chunk <= 0)
return [];
}
int count = (int)Math.Min(int.MaxValue, ((length - 1) / chunk) + 1);
List<string> parts = new(count);
for (int i = 0; i < count; i++)
parts.Add(XisoSplitter.PartPath(splitBase, i));
return parts;
}
catch
{
// Probing must never fail the command; Split reports real errors.
return [];
}
}
/// <summary>
/// Runs a batch conversion plan: resolves every output (rejecting
/// duplicate outputs and outputs that would clobber an input), applies
/// <c>--skip-existing</c> and the overwrite prompt, then converts the
/// remaining sources sequentially or with <c>--jobs</c> workers.
/// </summary>
/// <param name="verb">Verb name used in status and summary lines.</param>
/// <param name="options">Parsed batch flags.</param>
/// <param name="sources">Full source paths, in deterministic order.</param>
/// <param name="outputFor">Maps a source to its primary output path.</param>
/// <param name="targetsFor">Maps a source and its primary output to every file it writes (split parts included).</param>
/// <param name="worker">Performs one conversion; returns 0 on success.</param>
/// <param name="guard">Optional input/output guard returning an error line to refuse the plan.</param>
internal static int Run(
string verb,
BatchOptions options,
IReadOnlyList<string> sources,
Func<string, string> outputFor,
Func<string, string, IReadOnlyList<string>> targetsFor,
Func<string, string, int> worker,
Func<string, string, string?>? guard = null)
{
if (options.DeleteSource && (options.AssumeNo || !options.AssumeYes))
{
Logger.LogErr("Error: --delete-source requires -y/--yes and cannot be combined with -n/--no\n");
return 1;
}
Logger.Log($"batch {verb}: {sources.Count} file(s) from {options.Directory}" +
$"{(options.Recursive ? " (recursive)" : "")}\n");
HashSet<string> sourceSet = new(sources, StringComparer.OrdinalIgnoreCase);
HashSet<string> seenOutputs = new(StringComparer.OrdinalIgnoreCase);
HashSet<string> targetSet = new(StringComparer.OrdinalIgnoreCase);
List<BatchItem> plan = new(sources.Count);
foreach (string source in sources)
{
string output = outputFor(source);
string? refusal = guard?.Invoke(source, output);
if (refusal != null)
{
Logger.LogErr(refusal);
return 1;
}
if (sourceSet.Contains(output))
{
Logger.LogErr($"Error: {verb} output {output} is also a batch input; choose another name\n");
return 1;
}
if (!seenOutputs.Add(output))
{
Logger.LogErr($"Error: {verb} outputs collide on {output}; " +
"use --output-name to keep them distinct\n");
return 1;
}
foreach (string target in targetsFor(source, output))
{
if (sourceSet.Contains(Path.GetFullPath(target)))
{
Logger.LogErr($"Error: {verb} output part {target} is also a batch input; " +
"choose another name\n");
return 1;
}
targetSet.Add(Path.GetFullPath(target));
}
plan.Add(new BatchItem(source, output));
}
if (options.DeleteSource)
{
// Never delete an input that another item writes. The planning
// checks above already reject such plans; this is the final guard.
foreach (string source in sources)
{
foreach (string sourceFile in SourceFiles(source))
{
if (targetSet.Contains(sourceFile))
{
Logger.LogErr($"Error: {verb} cannot delete source {sourceFile}; " +
"it is also a batch output\n");
return 1;
}
}
}
}
int converted = 0;
int skipped = 0;
int failed = 0;
int deleted = 0;
List<BatchItem> ready = new(plan.Count);
foreach (BatchItem item in plan)
{
IReadOnlyList<string> targets = targetsFor(item.Source, item.Output);
List<string> existing = targets
.Where(t => File.Exists(t) || Directory.Exists(t))
.ToList();
bool complete = targets.Count > 0 && existing.Count == targets.Count;
// --skip-existing means "skip a finished conversion". For a split
// output, every expected part must exist; a partial set is resumed
// (and overwritten) instead of being mistaken for a complete one.
if (complete && options.SkipExisting)
{
skipped++;
Logger.Log($"{verb}: {Path.GetFileName(item.Source)} -> " +
$"{Path.GetFileName(item.Output)} [SKIP] output exists\n");
continue;
}
if (existing.Count > 0 && !options.SkipExisting)
{
if (options.AssumeNo)
{
skipped++;
Logger.Log($"{verb}: {Path.GetFileName(item.Source)} -> " +
$"{Path.GetFileName(item.Output)} [SKIP] output exists\n");
continue;
}
bool confirmed = true;
foreach (string target in existing)
{
if (!OverwritePrompt.ConfirmOverwrite(target, options.AssumeYes, options.AssumeNo))
{
confirmed = false;
break;
}
}
if (!confirmed)
{
failed++;
Logger.LogErr($"{verb}: {Path.GetFileName(item.Source)} [FAIL] output exists\n");
if (!options.ContinueOnError)
break;
continue;
}
}
ready.Add(item);
}
if (ready.Count > 0 && options.Jobs > 1 && ready.Count > 1)
{
int parallelConverted = 0;
int parallelFailed = 0;
using CancellationTokenSource cancellation = new();
try
{
Parallel.ForEach(ready,
new ParallelOptions { MaxDegreeOfParallelism = options.Jobs, CancellationToken = cancellation.Token },
item =>
{
if (Execute(item) == 0)
{
Interlocked.Increment(ref parallelConverted);
}
else
{
Interlocked.Increment(ref parallelFailed);
if (!options.ContinueOnError)
// Parallel.ForEach returns only after every iteration
// finishes, so the CTS is still alive here.
// ReSharper disable once AccessToDisposedClosure
cancellation.Cancel();
}
});
}
catch (OperationCanceledException)
{
// First failure without --continue-on-error stopped the run.
}
converted += parallelConverted;
failed += parallelFailed;
}
else
{
foreach (BatchItem item in ready)
{
if (Execute(item) == 0)
{
converted++;
}
else
{
failed++;
if (!options.ContinueOnError)
break;
}
}
}
string summary = $"batch {verb}: {converted} converted, {skipped} skipped, {failed} failed";
if (options.DeleteSource)
summary += $", {deleted} deleted";
Logger.Log(summary + "\n");
return failed == 0 ? 0 : 1;
int Execute(BatchItem item)
{
try
{
string? outputDirectory = Path.GetDirectoryName(item.Output);
if (!string.IsNullOrEmpty(outputDirectory))
Directory.CreateDirectory(outputDirectory);
int rc = worker(item.Source, item.Output);
if (rc != 0)
{
Logger.LogErr($"{verb}: {Path.GetFileName(item.Source)} [FAIL] exit code {rc}\n");
DeleteFailedOutputs(item);
return 1;
}
if (options.DeleteSource && !TryDeleteSource(item.Source, out string? deleteError))
{
Logger.LogErr($"{verb}: {Path.GetFileName(item.Source)} [FAIL] converted but " +
$"could not delete source: {deleteError}\n");
return 1;
}
Logger.Log($"{verb}: {Path.GetFileName(item.Source)} -> " +
$"{Path.GetFileName(item.Output)} [OK]\n");
return 0;
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
Logger.LogErr($"{verb}: {Path.GetFileName(item.Source)} [FAIL] {ex.Message}\n");
DeleteFailedOutputs(item);
return 1;
}
}
bool TryDeleteSource(string source, out string? error)
{
error = null;
try
{
IReadOnlyList<string> files = SourceFiles(source);
foreach (string file in files)
{
if (targetSet.Contains(file))
{
error = $"{file} is also a batch output";
return false;
}
}
foreach (string file in files)
{
if (File.Exists(file))
File.Delete(file);
}
Interlocked.Increment(ref deleted);
return true;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or
ArgumentException or NotSupportedException)
{
error = ex.Message;
return false;
}
}
void DeleteFailedOutputs(BatchItem item)
{
// A failed conversion must not leave a truncated output behind
// (CisoReader creates the destination before it validates the
// header). The overwrite prompt already authorized replacing any
// pre-existing target, so removing the partial file is safe.
try
{
foreach (string target in targetsFor(item.Source, item.Output))
{
if (File.Exists(target))
File.Delete(target);
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Logger.LogErr($"{verb}: could not remove partial output for " +
$"{Path.GetFileName(item.Source)}: {ex.Message}\n");
}
}
}
/// <summary>One source/output pair in a batch plan.</summary>
private readonly record struct BatchItem(string Source, string Output);
}