- Notifications
You must be signed in to change notification settings - Fork3
feat: wire up file sync window#64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
49 changes: 42 additions & 7 deletionsApp/App.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletionsApp/Models/RpcModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletionsApp/Models/SyncSessionControllerStateModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
namespace Coder.Desktop.App.Models; | ||
public enum SyncSessionControllerLifecycle | ||
{ | ||
// Uninitialized means that the daemon has not been started yet. This can | ||
// be resolved by calling RefreshState (or any other RPC method | ||
// successfully). | ||
Uninitialized, | ||
// Stopped means that the daemon is not running. This could be because: | ||
// - It was never started (pre-Initialize) | ||
// - It was stopped due to no sync sessions (post-Initialize, post-operation) | ||
// - The last start attempt failed (DaemonError will be set) | ||
// - The last daemon process crashed (DaemonError will be set) | ||
Stopped, | ||
// Running is the normal state where the daemon is running and managing | ||
// sync sessions. This is only set after a successful start (including | ||
// being able to connect to the daemon). | ||
Running, | ||
} | ||
public class SyncSessionControllerStateModel | ||
{ | ||
public SyncSessionControllerLifecycle Lifecycle { get; init; } = SyncSessionControllerLifecycle.Stopped; | ||
/// <summary> | ||
/// May be set when Lifecycle is Stopped to signify that the daemon failed | ||
/// to start or unexpectedly crashed. | ||
/// </summary> | ||
public string? DaemonError { get; init; } | ||
public required string DaemonLogFilePath { get; init; } | ||
/// <summary> | ||
/// This contains the last known state of all sync sessions. Sync sessions | ||
/// are periodically refreshed if the daemon is running. This list is | ||
/// sorted by creation time. | ||
/// </summary> | ||
public IReadOnlyList<SyncSessionModel> SyncSessions { get; init; } = []; | ||
} |
129 changes: 90 additions & 39 deletionsApp/Models/SyncSessionModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Coder.Desktop.App.Converters; | ||
using Coder.Desktop.MutagenSdk.Proto.Synchronization; | ||
using Coder.Desktop.MutagenSdk.Proto.Synchronization.Core; | ||
using Coder.Desktop.MutagenSdk.Proto.Url; | ||
namespace Coder.Desktop.App.Models; | ||
@@ -48,7 +51,7 @@ public string Description(string linePrefix = "") | ||
public class SyncSessionModel | ||
{ | ||
public readonly string Identifier; | ||
deansheather marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
public readonlyDateTime CreatedAt; | ||
public readonly string AlphaName; | ||
public readonly string AlphaPath; | ||
@@ -62,14 +65,24 @@ public class SyncSessionModel | ||
public readonly SyncSessionModelEndpointSize AlphaSize; | ||
public readonly SyncSessionModelEndpointSize BetaSize; | ||
public readonly IReadOnlyList<string> Conflicts; // Conflict descriptions | ||
public readonly ulong OmittedConflicts; | ||
public readonly IReadOnlyList<string> Errors; | ||
// If Paused is true, the session can be resumed. If false, the session can | ||
// be paused. | ||
public bool Paused => StatusCategory is SyncSessionStatusCategory.Paused or SyncSessionStatusCategory.Halted; | ||
public string StatusDetails | ||
{ | ||
get | ||
{ | ||
var str = StatusString; | ||
if (StatusCategory.ToString() != StatusString) str += $" ({StatusCategory})"; | ||
str += $"\n\n{StatusDescription}"; | ||
foreach (var err in Errors) str += $"\n\n-----\n\n{err}"; | ||
foreach (var conflict in Conflicts) str += $"\n\n-----\n\n{conflict}"; | ||
if (OmittedConflicts > 0) str += $"\n\n-----\n\n{OmittedConflicts:N0} conflicts omitted"; | ||
return str; | ||
} | ||
} | ||
@@ -84,41 +97,10 @@ public string SizeDetails | ||
} | ||
} | ||
public SyncSessionModel(State state) | ||
{ | ||
Identifier = state.Session.Identifier; | ||
CreatedAt = state.Session.CreationTime.ToDateTime(); | ||
(AlphaName, AlphaPath) = NameAndPathFromUrl(state.Session.Alpha); | ||
(BetaName, BetaPath) = NameAndPathFromUrl(state.Session.Beta); | ||
@@ -220,6 +202,9 @@ public SyncSessionModel(State state) | ||
StatusDescription = "The session has conflicts that need to be resolved."; | ||
} | ||
Conflicts = state.Conflicts.Select(ConflictToString).ToList(); | ||
OmittedConflicts = state.ExcludedConflicts; | ||
AlphaSize = new SyncSessionModelEndpointSize | ||
{ | ||
SizeBytes = state.AlphaState.TotalFileSize, | ||
@@ -235,9 +220,24 @@ public SyncSessionModel(State state) | ||
SymlinkCount = state.BetaState.SymbolicLinks, | ||
}; | ||
List<string> errors = []; | ||
if (!string.IsNullOrWhiteSpace(state.LastError)) errors.Add($"Last error:\n {state.LastError}"); | ||
// TODO: scan problems + transition problems + omissions should probably be fields | ||
foreach (var scanProblem in state.AlphaState.ScanProblems) errors.Add($"Alpha scan problem: {scanProblem}"); | ||
if (state.AlphaState.ExcludedScanProblems > 0) | ||
errors.Add($"Alpha scan problems omitted: {state.AlphaState.ExcludedScanProblems}"); | ||
foreach (var scanProblem in state.AlphaState.ScanProblems) errors.Add($"Beta scan problem: {scanProblem}"); | ||
if (state.BetaState.ExcludedScanProblems > 0) | ||
errors.Add($"Beta scan problems omitted: {state.BetaState.ExcludedScanProblems}"); | ||
foreach (var transitionProblem in state.AlphaState.TransitionProblems) | ||
errors.Add($"Alpha transition problem: {transitionProblem}"); | ||
if (state.AlphaState.ExcludedTransitionProblems > 0) | ||
errors.Add($"Alpha transition problems omitted: {state.AlphaState.ExcludedTransitionProblems}"); | ||
foreach (var transitionProblem in state.AlphaState.TransitionProblems) | ||
errors.Add($"Beta transition problem: {transitionProblem}"); | ||
if (state.BetaState.ExcludedTransitionProblems > 0) | ||
errors.Add($"Beta transition problems omitted: {state.BetaState.ExcludedTransitionProblems}"); | ||
Errors = errors; | ||
} | ||
private static (string, string) NameAndPathFromUrl(URL url) | ||
@@ -251,4 +251,55 @@ private static (string, string) NameAndPathFromUrl(URL url) | ||
return (name, path); | ||
} | ||
private static string ConflictToString(Conflict conflict) | ||
{ | ||
string? friendlyProblem = null; | ||
if (conflict.AlphaChanges.Count == 1 && conflict.BetaChanges.Count == 1 && | ||
conflict.AlphaChanges[0].Old == null && | ||
conflict.BetaChanges[0].Old == null && | ||
conflict.AlphaChanges[0].New != null && | ||
conflict.BetaChanges[0].New != null) | ||
friendlyProblem = | ||
"An entry was created on both endpoints and they do not match. You can resolve this conflict by deleting one of the entries on either side."; | ||
var str = $"Conflict at path '{conflict.Root}':"; | ||
foreach (var change in conflict.AlphaChanges) | ||
str += $"\n (alpha) {ChangeToString(change)}"; | ||
foreach (var change in conflict.BetaChanges) | ||
str += $"\n (beta) {ChangeToString(change)}"; | ||
if (friendlyProblem != null) | ||
str += $"\n\n{friendlyProblem}"; | ||
return str; | ||
} | ||
private static string ChangeToString(Change change) | ||
{ | ||
return $"{change.Path} ({EntryToString(change.Old)} -> {EntryToString(change.New)})"; | ||
} | ||
private static string EntryToString(Entry? entry) | ||
{ | ||
if (entry == null) return "<non-existent>"; | ||
var str = entry.Kind.ToString(); | ||
switch (entry.Kind) | ||
{ | ||
case EntryKind.Directory: | ||
str += $" ({entry.Contents.Count} entries)"; | ||
break; | ||
case EntryKind.File: | ||
var digest = BitConverter.ToString(entry.Digest.ToByteArray()).Replace("-", "").ToLower(); | ||
str += $" ({digest}, executable: {entry.Executable})"; | ||
break; | ||
case EntryKind.SymbolicLink: | ||
str += $" (target: {entry.Target})"; | ||
break; | ||
case EntryKind.Problematic: | ||
str += $" ({entry.Problem})"; | ||
break; | ||
} | ||
return str; | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.