fix(copies): address the owner review 6 findings
The review of the found-copies work showed pairs that could stick, jobs that could act on a pair the user had answered otherwise, and detection gaps: - forgetting a link on an address-keyed server deletes the pair and Candidate rows of that remote and resets the probe, so the sequence is found again when it is back; a Linked/Integrated row with no link is asked again - 404s count only on id-keyed servers, at most once per recheck interval - probes store the server's newest update time (copy_probes.server_newest, migration 0012) instead of comparing with this PC's clock; the lookup sample carries hashed photos by size and capture time too, for servers that have not hashed their copy - the older-server gate no longer re-compares unchanged manifests - a failed Integrate keeps its job id so a retry resumes only an untouched pair; cancel and stale plans release the pair (ReleaseAsync) - automatic photo transfers never create or retarget a sequence - a first upload files photos the server holds elsewhere into the new sequence - Unlink re-compares before keeping apart; Trash here names only true last copies; Drop... trashes one version on both sides after re-checking the other - a merge keeping the pair's other sequence swaps the dialog's columns and re-keys Different choices; Upload all reads every pair Each fix has a regression test where it makes sense. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
96b5b4078b
commit
fe752a0a21
33 files changed
+957
-123
No files matched your search
@@ -6,19 +6,22 @@ namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// A detail that differs (the Details part): its label, this PC's and the other side's value, and the side both take
|
||||
/// (nothing preselected: <see cref="ChoiceIndex"/> -1 until the user picks).
|
||||
/// (nothing preselected: <see cref="ChoiceIndex"/> -1 until the user picks). In a merge the first column is the kept
|
||||
/// sequence's: <paramref name="swapped"/> when that is the pair's other sequence (the line compares the pair's first with it).
|
||||
/// </summary>
|
||||
public sealed class CopyDetailRow(DetailLine line, bool isMerge, Action changed) : ObservableObject
|
||||
public sealed class CopyDetailRow(DetailLine line, bool isMerge, Action changed, bool swapped = false) : ObservableObject
|
||||
{
|
||||
private int _choiceIndex = -1;
|
||||
|
||||
public DetailLine Line { get; } = line;
|
||||
public string Path => Line.Path;
|
||||
public string Label => SyncText.DetailLabel(Line.Path);
|
||||
public string HereText => Value(Line.Here);
|
||||
public string ThereText => Value(Line.There);
|
||||
public string HereToolTip => Line.Here ?? Loc.L("Server.Sync.None");
|
||||
public string ThereToolTip => Line.There ?? Loc.L("Server.Sync.None");
|
||||
private string? First => swapped ? Line.There : Line.Here;
|
||||
private string? Second => swapped ? Line.Here : Line.There;
|
||||
public string HereText => Value(First);
|
||||
public string ThereText => Value(Second);
|
||||
public string HereToolTip => First ?? Loc.L("Server.Sync.None");
|
||||
public string ThereToolTip => Second ?? Loc.L("Server.Sync.None");
|
||||
|
||||
public string HereWord => Loc.L(isMerge ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.ThisPc");
|
||||
public string ThereWord => Loc.L(isMerge ? "Server.Copies.Detail.Other" : "Server.Copies.Detail.Server");
|
||||
|
||||
@@ -202,8 +202,11 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
public int Unchosen => _details.Count(d => d.Chosen is null);
|
||||
public ICommand AllHereCommand { get; }
|
||||
public ICommand AllThereCommand { get; }
|
||||
public string AllHereText => Loc.L("Server.Copies.Detail.AllThisPc");
|
||||
public string AllThereText => Loc.L("Server.Copies.Detail.AllServer");
|
||||
public string AllHereText => Loc.L(IsMerge ? "Server.Copies.Detail.AllKept" : "Server.Copies.Detail.AllThisPc");
|
||||
public string AllThereText => Loc.L(IsMerge ? "Server.Copies.Detail.AllOther" : "Server.Copies.Detail.AllServer");
|
||||
|
||||
/// <summary>A merge keeping the pair's other sequence: the review compares the pair's first with it, so its two columns swap.</summary>
|
||||
private bool Swapped => IsMerge && _keepId is { } keep && keep == Copy.OtherId;
|
||||
|
||||
// ---- Projects ----
|
||||
|
||||
@@ -337,9 +340,7 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
?? _classes.FirstOrDefault(c => c.Class is not (PhotoClass.Same or PhotoClass.Converted))
|
||||
?? _classes.FirstOrDefault();
|
||||
BuildPhotos();
|
||||
var chosen = _details.ToDictionary(d => d.Path, d => d.ChoiceIndex);
|
||||
Details = [.. review.Details.Select(line => new CopyDetailRow(line, IsMerge, Changed))];
|
||||
foreach (var row in _details) row.SetQuietly(chosen.GetValueOrDefault(row.Path, -1));
|
||||
BuildDetails(review);
|
||||
HereProjects = [.. review.Projects.Here.Select(p => new CopyProjectRow(p))];
|
||||
ThereProjects = [.. review.Projects.There.Select(p => new CopyProjectRow(p))];
|
||||
if (IsMerge)
|
||||
@@ -349,6 +350,22 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The detail rows, oriented to the kept sequence, each keeping the side chosen (0 is always the kept, or this PC).</summary>
|
||||
private void BuildDetails(CopyReview review)
|
||||
{
|
||||
var chosen = _details.GroupBy(d => d.Path, StringComparer.Ordinal).ToDictionary(g => g.Key, g => g.First().ChoiceIndex, StringComparer.Ordinal);
|
||||
Details = [.. review.Details.Select(line => new CopyDetailRow(line, IsMerge, Changed, Swapped))];
|
||||
foreach (var row in _details) row.SetQuietly(chosen.GetValueOrDefault(row.Path, -1));
|
||||
}
|
||||
|
||||
/// <summary>The kept sequence changed sides: the columns follow it.</summary>
|
||||
private void Reorient(bool wasSwapped)
|
||||
{
|
||||
if (wasSwapped == Swapped || _review is not { } review) return;
|
||||
BuildDetails(review);
|
||||
BuildPhotos();
|
||||
}
|
||||
|
||||
private void BuildPhotos()
|
||||
{
|
||||
var review = _review;
|
||||
@@ -359,7 +376,8 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
Photos = review is null || cls is null ? []
|
||||
: [.. review.Photos.Of(cls.Value).Select(p => new CopyPhotoRow(p, IsMerge,
|
||||
choosing && !IsMerge && cls is PhotoClass.OnlyHere or PhotoClass.OnlyThere,
|
||||
choosing && cls == PhotoClass.Differs, choices, _perPhoto.TryGetValue(p.Key, out var c) ? c : null, () => OnPhotoChanged(p.Key), drop))];
|
||||
choosing && cls == PhotoClass.Differs, choices, _perPhoto.TryGetValue(p.Key, out var c) ? c : null, () => OnPhotoChanged(p.Key), drop,
|
||||
Swapped))];
|
||||
foreach (var row in _photos) row.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName != nameof(CopyPhotoRow.IsSelected)) return;
|
||||
@@ -403,8 +421,10 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
|
||||
private void Keep(CopyKeepOption option)
|
||||
{
|
||||
var wasSwapped = Swapped;
|
||||
_keepId = option.SequenceId;
|
||||
foreach (var other in _keep.Where(o => !ReferenceEquals(o, option))) other.SetQuietly(false);
|
||||
Reorient(wasSwapped);
|
||||
OnPropertyChanged(nameof(HereHeading));
|
||||
OnPropertyChanged(nameof(ThereHeading));
|
||||
Changed();
|
||||
@@ -441,8 +461,21 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
private IntegrateChoices IntegrateChoices() => new(_policy.Value, IsChoosing ? new Dictionary<string, PhotoChoice>(_perPhoto) : new Dictionary<string, PhotoChoice>(),
|
||||
DetailChoices(), _projectsIndex == 0 ? CopyProjects.CopyAcross : CopyProjects.Leave);
|
||||
|
||||
private MergeChoices MergeChoices() => new(_policy.Value, IsChoosing ? new Dictionary<string, PhotoChoice>(_perPhoto) : new Dictionary<string, PhotoChoice>(),
|
||||
DetailChoices());
|
||||
private MergeChoices MergeChoices() => new(_policy.Value, IsChoosing ? MergePerPhoto() : new Dictionary<string, PhotoChoice>(), DetailChoices());
|
||||
|
||||
/// <summary>
|
||||
/// The per-photo choices as the merge reads them: a Different photo is keyed by the kept sequence's version, so when the
|
||||
/// kept one is the pair's other sequence the review's key (the pair's first's version) becomes the other's.
|
||||
/// </summary>
|
||||
private Dictionary<string, PhotoChoice> MergePerPhoto()
|
||||
{
|
||||
if (!Swapped || _review is not { } review) return new Dictionary<string, PhotoChoice>(_perPhoto);
|
||||
var differs = review.Photos.Of(PhotoClass.Differs).ToDictionary(p => p.Key, StringComparer.Ordinal);
|
||||
var result = new Dictionary<string, PhotoChoice>(StringComparer.Ordinal);
|
||||
foreach (var (key, choice) in _perPhoto)
|
||||
result[differs.TryGetValue(key, out var p) && p.There?.Sha256 is { Length: > 0 } kept ? kept.ToLowerInvariant() : key] = choice;
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<string, CopySide> DetailChoices() =>
|
||||
_details.Where(d => d.Chosen is not null).ToDictionary(d => d.Path, d => d.Chosen!.Value, StringComparer.Ordinal);
|
||||
@@ -460,8 +493,10 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
_merge = merge;
|
||||
if (_keepId is null && !merge.Blocks.Contains(CopyBlock.KeptUnchosen) && merge.KeepId != Guid.Empty)
|
||||
{
|
||||
var wasSwapped = Swapped;
|
||||
_keepId = merge.KeepId;
|
||||
foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
|
||||
Reorient(wasSwapped);
|
||||
}
|
||||
}
|
||||
else if (_shell.Services.Sync.Remote is { } remote && string.Equals(_shell.Services.Sync.Server, Copy.Server, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -645,11 +680,38 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drop…: this version of a Two versions photo goes to the trash of each side that holds it, after a confirmed plan.</summary>
|
||||
/// <summary>
|
||||
/// Drop…: this version of a Two versions photo goes to the trash of both sides (this PC's and the server's, or both local
|
||||
/// copies), after one confirmed plan; refused unless the other version stays on both.
|
||||
/// </summary>
|
||||
private async Task DropAsync(CopyPhotoRow row)
|
||||
{
|
||||
if (row.Photo.Here is not null) await TrashHereAsync([row.Key]);
|
||||
if (row.Photo.There is not null && !IsMerge) await TrashThereAsync([row.Key]);
|
||||
var remote = Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null;
|
||||
if (Copy.Kind == CopyKind.LocalServer && remote is null) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var plan = await _engine.PlanDropVersionAsync(Copy.Id, row.Key, remote, CancellationToken.None);
|
||||
var names = plan.Here.Frames.Select(f => f.FileName).Concat(plan.Other?.Frames.Select(f => f.FileName) ?? []).DefaultIfEmpty(row.Name);
|
||||
var request = TrashRequest(plan.Photos, names, Loc.L("Tooltips.Server.Copies.Drop"), plan.LastCopies);
|
||||
if (!_shell.Services.Dialogs.Confirm(request)) return;
|
||||
await _engine.DropVersionAsync(plan, remote, CancellationToken.None);
|
||||
}
|
||||
catch (StaleCopyPlanException ex)
|
||||
{
|
||||
ShowMessage(ex.Message);
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
/// <summary>To trash…: the dry run of moving these photos of this PC's copy to its archive trash, the confirmation, then the move.</summary>
|
||||
@@ -659,13 +721,13 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var plan = await _engine.PlanTrashHereAsync(Copy.Id, keys, CancellationToken.None);
|
||||
var (plan, lasts) = await _engine.PlanTrashHereAsync(Copy.Id, keys, CancellationToken.None);
|
||||
if (plan.Frames.Count == 0)
|
||||
{
|
||||
ShowMessage(Loc.L("Errors.Copies.NotThere"));
|
||||
return;
|
||||
}
|
||||
var request = TrashRequest(plan.Frames.Count, plan.Frames.Select(f => f.FileName), Loc.L("Tooltips.Server.Copies.ToTrash"), []);
|
||||
var request = TrashRequest(plan.Frames.Count, plan.Frames.Select(f => f.FileName), Loc.L("Tooltips.Server.Copies.ToTrash"), lasts);
|
||||
if (!_shell.Services.Dialogs.Confirm(request)) return;
|
||||
await _engine.TrashHereAsync(Copy.Id, plan, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
|
||||
}
|
||||
|
||||
@@ -131,6 +131,9 @@ public sealed class CopyListViewModel : ObservableObject, IDisposable
|
||||
Follow(null);
|
||||
}
|
||||
|
||||
/// <summary>Every pair of the index at the last reload (any server, local pairs, plain links): what Upload all's tooltip counts.</summary>
|
||||
public IReadOnlyList<FoundCopy> AllPairs { get; private set; } = [];
|
||||
|
||||
/// <summary>The pair the sequence is in (this server's or a local one), the one asking for a choice first; null when none.</summary>
|
||||
public FoundCopy? PairOf(Guid sequenceId) => _pairs
|
||||
.Where(p => p.Copy.LocalId == sequenceId || p.Copy.OtherId == sequenceId || p.Copy.RemoteId == sequenceId)
|
||||
@@ -149,6 +152,7 @@ public sealed class CopyListViewModel : ObservableObject, IDisposable
|
||||
{
|
||||
var server = Host.Server;
|
||||
var all = Engine is { } engine ? await engine.ListAsync(CancellationToken.None) : [];
|
||||
AllPairs = Engine is { } stored ? await stored.ListAllPairsAsync(CancellationToken.None) : [];
|
||||
_pairs = [.. CopyText.Sorted(all.Where(p => p.Copy.Kind == CopyKind.LocalLocal
|
||||
|| string.Equals(p.Copy.Server, server, StringComparison.OrdinalIgnoreCase)))];
|
||||
AnnounceDeletions();
|
||||
|
||||
@@ -29,15 +29,18 @@ public sealed class CopyClassRow(PhotoClassTotal total) : ObservableObject
|
||||
public sealed class CopyPhotoRow : ObservableObject
|
||||
{
|
||||
private readonly Action _changed;
|
||||
private readonly bool _swapped;
|
||||
private bool _bring;
|
||||
private bool _isSelected;
|
||||
private SettingsOption<PhotoChoice>? _choice;
|
||||
|
||||
/// <param name="swapped">A merge keeping the pair's other sequence: the photo's second side is the kept one.</param>
|
||||
public CopyPhotoRow(ComparedPhoto photo, bool isMerge, bool canBring, bool canChoose, IReadOnlyList<SettingsOption<PhotoChoice>> choices,
|
||||
PhotoChoice? current, Action changed, Func<CopyPhotoRow, Task>? drop)
|
||||
PhotoChoice? current, Action changed, Func<CopyPhotoRow, Task>? drop, bool swapped = false)
|
||||
{
|
||||
Photo = photo;
|
||||
IsMerge = isMerge;
|
||||
_swapped = isMerge && swapped;
|
||||
CanBring = canBring;
|
||||
CanChoose = canChoose;
|
||||
Choices = choices;
|
||||
@@ -118,6 +121,6 @@ public sealed class CopyPhotoRow : ObservableObject
|
||||
OnPropertyChanged(nameof(ChoiceAccessibleName));
|
||||
}
|
||||
|
||||
private string Side(bool here) => Loc.L(IsMerge ? (here ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
|
||||
private string Side(bool here) => Loc.L(IsMerge ? (here != _swapped ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
|
||||
: here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server");
|
||||
}
|
||||
Reference in new issue
Block a user