From 9ba0610338510938afab62f25a5a3104749136a9 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 11 Mar 2025 22:28:34 +1100 Subject: [PATCH 1/2] Add multiple proto "entry points" to MutagenSdk - Adds support for an array of protobuf "entry points" - Refactors file modification/writing to be more efficient and to not include an unnecessary byte order mark and two trailing new lines --- .../filesystem/behavior/probe_mode.proto | 3 +- MutagenSdk/Proto/selection/selection.proto | 3 +- MutagenSdk/Proto/service/daemon/daemon.proto | 53 +++++++++++++++++++ .../synchronization/synchronization.proto | 5 +- .../compression/algorithm.proto | 3 +- .../Proto/synchronization/configuration.proto | 3 +- .../Proto/synchronization/core/change.proto | 3 +- .../Proto/synchronization/core/conflict.proto | 3 +- .../Proto/synchronization/core/entry.proto | 3 +- .../core/ignore/ignore_vcs_mode.proto | 3 +- .../synchronization/core/ignore/syntax.proto | 3 +- .../Proto/synchronization/core/mode.proto | 3 +- .../core/permissions_mode.proto | 3 +- .../Proto/synchronization/core/problem.proto | 3 +- .../core/symbolic_link_mode.proto | 3 +- .../synchronization/hashing/algorithm.proto | 3 +- .../Proto/synchronization/rsync/receive.proto | 3 +- .../Proto/synchronization/scan_mode.proto | 3 +- .../Proto/synchronization/session.proto | 3 +- .../Proto/synchronization/stage_mode.proto | 3 +- MutagenSdk/Proto/synchronization/state.proto | 3 +- .../Proto/synchronization/version.proto | 3 +- .../Proto/synchronization/watch_mode.proto | 3 +- MutagenSdk/Proto/url/url.proto | 3 +- MutagenSdk/Update-Proto.ps1 | 34 +++++++----- 25 files changed, 97 insertions(+), 61 deletions(-) create mode 100644 MutagenSdk/Proto/service/daemon/daemon.proto diff --git a/MutagenSdk/Proto/filesystem/behavior/probe_mode.proto b/MutagenSdk/Proto/filesystem/behavior/probe_mode.proto index c804d84..ecbaf4a 100644 --- a/MutagenSdk/Proto/filesystem/behavior/probe_mode.proto +++ b/MutagenSdk/Proto/filesystem/behavior/probe_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/filesystem/behavior/probe_mode.proto * @@ -48,4 +48,3 @@ enum ProbeMode { // ProbeMode_ProbeModeProbe. ProbeModeAssume = 2; } - diff --git a/MutagenSdk/Proto/selection/selection.proto b/MutagenSdk/Proto/selection/selection.proto index c4a0c20..55cddb1 100644 --- a/MutagenSdk/Proto/selection/selection.proto +++ b/MutagenSdk/Proto/selection/selection.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/selection/selection.proto * @@ -45,4 +45,3 @@ message Selection { // it indicates that this selector should be used to select sessions. string labelSelector = 3; } - diff --git a/MutagenSdk/Proto/service/daemon/daemon.proto b/MutagenSdk/Proto/service/daemon/daemon.proto new file mode 100644 index 0000000..f810b3e --- /dev/null +++ b/MutagenSdk/Proto/service/daemon/daemon.proto @@ -0,0 +1,53 @@ +/* + * This file was taken from + * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/service/daemon/daemon.proto + * + * MIT License + * + * Copyright (c) 2016-present Docker, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +syntax = "proto3"; + +package daemon; +option csharp_namespace = "Coder.Desktop.MutagenSdk.Proto.Service.Daemon"; + +option go_package = "github.com/mutagen-io/mutagen/pkg/service/daemon"; + +message VersionRequest{} + +message VersionResponse { + // TODO: Should we encapsulate these inside a Version message type, perhaps + // in the mutagen package? + uint64 major = 1; + uint64 minor = 2; + uint64 patch = 3; + string tag = 4; +} + +message TerminateRequest{} + +message TerminateResponse{} + +service Daemon { + rpc Version(VersionRequest) returns (VersionResponse) {} + rpc Terminate(TerminateRequest) returns (TerminateResponse) {} +} diff --git a/MutagenSdk/Proto/service/synchronization/synchronization.proto b/MutagenSdk/Proto/service/synchronization/synchronization.proto index 0f978e2..1e3d6b2 100644 --- a/MutagenSdk/Proto/service/synchronization/synchronization.proto +++ b/MutagenSdk/Proto/service/synchronization/synchronization.proto @@ -1,6 +1,6 @@ -/* +/* * This file was taken from - * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/service\synchronization\synchronization.proto + * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/service/synchronization/synchronization.proto * * MIT License * @@ -167,4 +167,3 @@ service Synchronization { // Terminate terminates sessions. rpc Terminate(TerminateRequest) returns (TerminateResponse) {} } - diff --git a/MutagenSdk/Proto/synchronization/compression/algorithm.proto b/MutagenSdk/Proto/synchronization/compression/algorithm.proto index 857c1bc..96f972c 100644 --- a/MutagenSdk/Proto/synchronization/compression/algorithm.proto +++ b/MutagenSdk/Proto/synchronization/compression/algorithm.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/compression/algorithm.proto * @@ -47,4 +47,3 @@ enum Algorithm { // be used. AlgorithmZstandard = 3; } - diff --git a/MutagenSdk/Proto/synchronization/configuration.proto b/MutagenSdk/Proto/synchronization/configuration.proto index a115a49..3ba7fdc 100644 --- a/MutagenSdk/Proto/synchronization/configuration.proto +++ b/MutagenSdk/Proto/synchronization/configuration.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/configuration.proto * @@ -173,4 +173,3 @@ message Configuration { // Fields 82-90 are reserved for future compression configuration // parameters. } - diff --git a/MutagenSdk/Proto/synchronization/core/change.proto b/MutagenSdk/Proto/synchronization/core/change.proto index 0ea5b98..3779a25 100644 --- a/MutagenSdk/Proto/synchronization/core/change.proto +++ b/MutagenSdk/Proto/synchronization/core/change.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/change.proto * @@ -47,4 +47,3 @@ message Change { // nil if content has been deleted. Entry new = 3; } - diff --git a/MutagenSdk/Proto/synchronization/core/conflict.proto b/MutagenSdk/Proto/synchronization/core/conflict.proto index 717c164..ea46bef 100644 --- a/MutagenSdk/Proto/synchronization/core/conflict.proto +++ b/MutagenSdk/Proto/synchronization/core/conflict.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/conflict.proto * @@ -51,4 +51,3 @@ message Conflict { // BetaChanges are the relevant changes on beta. repeated Change betaChanges = 3; } - diff --git a/MutagenSdk/Proto/synchronization/core/entry.proto b/MutagenSdk/Proto/synchronization/core/entry.proto index be2d1fa..3b937a3 100644 --- a/MutagenSdk/Proto/synchronization/core/entry.proto +++ b/MutagenSdk/Proto/synchronization/core/entry.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/entry.proto * @@ -108,4 +108,3 @@ message Entry { // non-empty if and only if the entry represents problematic content. string problem = 15; } - diff --git a/MutagenSdk/Proto/synchronization/core/ignore/ignore_vcs_mode.proto b/MutagenSdk/Proto/synchronization/core/ignore/ignore_vcs_mode.proto index 5ad0da1..9a347c8 100644 --- a/MutagenSdk/Proto/synchronization/core/ignore/ignore_vcs_mode.proto +++ b/MutagenSdk/Proto/synchronization/core/ignore/ignore_vcs_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/ignore/ignore_vcs_mode.proto * @@ -45,4 +45,3 @@ enum IgnoreVCSMode { // should be propagated. IgnoreVCSModePropagate = 2; } - diff --git a/MutagenSdk/Proto/synchronization/core/ignore/syntax.proto b/MutagenSdk/Proto/synchronization/core/ignore/syntax.proto index 430f9cb..7db94d9 100644 --- a/MutagenSdk/Proto/synchronization/core/ignore/syntax.proto +++ b/MutagenSdk/Proto/synchronization/core/ignore/syntax.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/ignore/syntax.proto * @@ -45,4 +45,3 @@ enum Syntax { // semantics should be used. SyntaxDocker = 2; } - diff --git a/MutagenSdk/Proto/synchronization/core/mode.proto b/MutagenSdk/Proto/synchronization/core/mode.proto index 79678a2..56fbea9 100644 --- a/MutagenSdk/Proto/synchronization/core/mode.proto +++ b/MutagenSdk/Proto/synchronization/core/mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/mode.proto * @@ -68,4 +68,3 @@ enum SynchronizationMode { // deleting any extraneous contents on beta. SynchronizationModeOneWayReplica = 4; } - diff --git a/MutagenSdk/Proto/synchronization/core/permissions_mode.proto b/MutagenSdk/Proto/synchronization/core/permissions_mode.proto index d011f89..e16648f 100644 --- a/MutagenSdk/Proto/synchronization/core/permissions_mode.proto +++ b/MutagenSdk/Proto/synchronization/core/permissions_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/permissions_mode.proto * @@ -49,4 +49,3 @@ enum PermissionsMode { // perform any propagation of permissions. PermissionsModeManual = 2; } - diff --git a/MutagenSdk/Proto/synchronization/core/problem.proto b/MutagenSdk/Proto/synchronization/core/problem.proto index de4aad3..d58dec1 100644 --- a/MutagenSdk/Proto/synchronization/core/problem.proto +++ b/MutagenSdk/Proto/synchronization/core/problem.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/problem.proto * @@ -42,4 +42,3 @@ message Problem { // Error is a human-readable summary of the problem. string error = 2; } - diff --git a/MutagenSdk/Proto/synchronization/core/symbolic_link_mode.proto b/MutagenSdk/Proto/synchronization/core/symbolic_link_mode.proto index e9f0663..31bee64 100644 --- a/MutagenSdk/Proto/synchronization/core/symbolic_link_mode.proto +++ b/MutagenSdk/Proto/synchronization/core/symbolic_link_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/core/symbolic_link_mode.proto * @@ -52,4 +52,3 @@ enum SymbolicLinkMode { // and only makes sense in the context of POSIX-to-POSIX synchronization. SymbolicLinkModePOSIXRaw = 3; } - diff --git a/MutagenSdk/Proto/synchronization/hashing/algorithm.proto b/MutagenSdk/Proto/synchronization/hashing/algorithm.proto index 1e155c7..1cb2fa1 100644 --- a/MutagenSdk/Proto/synchronization/hashing/algorithm.proto +++ b/MutagenSdk/Proto/synchronization/hashing/algorithm.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/hashing/algorithm.proto * @@ -45,4 +45,3 @@ enum Algorithm { // Algorithm_AlgorithmXXH128 specifies that XXH128 hashing should be used. AlgorithmXXH128 = 3; } - diff --git a/MutagenSdk/Proto/synchronization/rsync/receive.proto b/MutagenSdk/Proto/synchronization/rsync/receive.proto index bb71149..7d6b3f2 100644 --- a/MutagenSdk/Proto/synchronization/rsync/receive.proto +++ b/MutagenSdk/Proto/synchronization/rsync/receive.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/rsync/receive.proto * @@ -55,4 +55,3 @@ message ReceiverState { // It would also be really nice to have TotalExpectedSize, but this is // prohibitively difficult and expensive to compute. } - diff --git a/MutagenSdk/Proto/synchronization/scan_mode.proto b/MutagenSdk/Proto/synchronization/scan_mode.proto index ea8c264..de1777f 100644 --- a/MutagenSdk/Proto/synchronization/scan_mode.proto +++ b/MutagenSdk/Proto/synchronization/scan_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/scan_mode.proto * @@ -45,4 +45,3 @@ enum ScanMode { // watch-based acceleration. ScanModeAccelerated = 2; } - diff --git a/MutagenSdk/Proto/synchronization/session.proto b/MutagenSdk/Proto/synchronization/session.proto index 49329ba..c23985f 100644 --- a/MutagenSdk/Proto/synchronization/session.proto +++ b/MutagenSdk/Proto/synchronization/session.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/session.proto * @@ -99,4 +99,3 @@ message Session { // NOTE: Fields 11, 12, 13, and 14 are used above. They are out of order for // historical reasons. } - diff --git a/MutagenSdk/Proto/synchronization/stage_mode.proto b/MutagenSdk/Proto/synchronization/stage_mode.proto index ffea648..247e0a9 100644 --- a/MutagenSdk/Proto/synchronization/stage_mode.proto +++ b/MutagenSdk/Proto/synchronization/stage_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/stage_mode.proto * @@ -49,4 +49,3 @@ enum StageMode { // function if the synchronization root already exists. StageModeInternal = 3; } - diff --git a/MutagenSdk/Proto/synchronization/state.proto b/MutagenSdk/Proto/synchronization/state.proto index ec816fe..24d7e3f 100644 --- a/MutagenSdk/Proto/synchronization/state.proto +++ b/MutagenSdk/Proto/synchronization/state.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/state.proto * @@ -158,4 +158,3 @@ message State { // BetaState encodes the state of the beta endpoint. It is always non-nil. EndpointState betaState = 8; } - diff --git a/MutagenSdk/Proto/synchronization/version.proto b/MutagenSdk/Proto/synchronization/version.proto index a9034a4..92a8c62 100644 --- a/MutagenSdk/Proto/synchronization/version.proto +++ b/MutagenSdk/Proto/synchronization/version.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/version.proto * @@ -42,4 +42,3 @@ enum Version { // Version1 represents session version 1. Version1 = 1; } - diff --git a/MutagenSdk/Proto/synchronization/watch_mode.proto b/MutagenSdk/Proto/synchronization/watch_mode.proto index 0f8515d..624aa0b 100644 --- a/MutagenSdk/Proto/synchronization/watch_mode.proto +++ b/MutagenSdk/Proto/synchronization/watch_mode.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/synchronization/watch_mode.proto * @@ -52,4 +52,3 @@ enum WatchMode { // (i.e. no events should be generated). WatchModeNoWatch = 3; } - diff --git a/MutagenSdk/Proto/url/url.proto b/MutagenSdk/Proto/url/url.proto index cfa337f..d514f5b 100644 --- a/MutagenSdk/Proto/url/url.proto +++ b/MutagenSdk/Proto/url/url.proto @@ -1,4 +1,4 @@ -/* +/* * This file was taken from * https://github.com/mutagen-io/mutagen/tree/v0.18.1/pkg/url/url.proto * @@ -89,4 +89,3 @@ message URL { // required and their behavior is dependent on the transport implementation. map parameters = 8; } - diff --git a/MutagenSdk/Update-Proto.ps1 b/MutagenSdk/Update-Proto.ps1 index 09f00fd..4bf2f94 100644 --- a/MutagenSdk/Update-Proto.ps1 +++ b/MutagenSdk/Update-Proto.ps1 @@ -8,7 +8,10 @@ $ErrorActionPreference = "Stop" $repo = "mutagen-io/mutagen" $protoPrefix = "pkg" -$entryFile = "service\synchronization\synchronization.proto" +$entryFiles = @( + "service/synchronization/synchronization.proto", + "service/daemon/daemon.proto" +) $outputNamespace = "Coder.Desktop.MutagenSdk.Proto" $outputDir = "MutagenSdk\Proto" @@ -53,15 +56,8 @@ $licenseContent = Get-Content (Join-Path $cloneDir "LICENSE") $mitStartIndex = $licenseContent.IndexOf("MIT License") $licenseHeader = ($licenseContent[$mitStartIndex..($licenseContent.Length - 1)] | ForEach-Object { (" * " + $_).TrimEnd() }) -join "`n" -$entryFilePath = Join-Path $cloneDir (Join-Path $protoPrefix $entryFile) -if (-not (Test-Path $entryFilePath)) { - throw "Failed to find $entryFilePath in mutagen repo" -} - # Map of src (in the mutagen repo) to dst (within the $outputDir). -$filesToCopy = @{ - $entryFilePath = $entryFile -} +$filesToCopy = @{} function Add-ImportedFiles([string] $path) { $content = Get-Content $path @@ -88,7 +84,14 @@ function Add-ImportedFiles([string] $path) { } } -Add-ImportedFiles $entryFilePath +foreach ($entryFile in $entryFiles) { + $entryFilePath = Join-Path $cloneDir (Join-Path $protoPrefix $entryFile) + if (-not (Test-Path $entryFilePath)) { + throw "Failed to find $entryFilePath in mutagen repo" + } + $filesToCopy[$entryFilePath] = $entryFile + Add-ImportedFiles $entryFilePath +} $repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..") Push-Location $repoRoot @@ -105,7 +108,6 @@ try { if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force } - Copy-Item -Force $filePath $dstPath # Determine the license header. $fileHeader = "/*`n" + @@ -125,14 +127,18 @@ try { $csharpNamespace += ".$csharpNamespaceSuffix" } - # Add the csharp_namespace declaration. - $content = Get-Content $dstPath -Raw + # Add the license header and csharp_namespace declaration. + $content = Get-Content $filePath -Raw $content = $fileHeader + $content $content = $content -replace '(?m)^(package .*?;)', "`$1`noption csharp_namespace = `"$csharpNamespace`";" # Replace all LF with CRLF to avoid spurious diffs in git. $content = $content -replace "(? Date: Tue, 11 Mar 2025 22:35:17 +1100 Subject: [PATCH 2/2] Add Daemon service to MutagenClient --- MutagenSdk/MutagenClient.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MutagenSdk/MutagenClient.cs b/MutagenSdk/MutagenClient.cs index 1b3e375..e740af6 100644 --- a/MutagenSdk/MutagenClient.cs +++ b/MutagenSdk/MutagenClient.cs @@ -1,3 +1,4 @@ +using Coder.Desktop.MutagenSdk.Proto.Service.Daemon; using Coder.Desktop.MutagenSdk.Proto.Service.Synchronization; using Grpc.Core; using Grpc.Net.Client; @@ -8,6 +9,7 @@ public class MutagenClient : IDisposable { private readonly GrpcChannel _channel; + public readonly Daemon.DaemonClient Daemon; public readonly Synchronization.SynchronizationClient Synchronization; public MutagenClient(string dataDir) @@ -39,11 +41,15 @@ public MutagenClient(string dataDir) ConnectCallback = connectionFactory.ConnectAsync, }; + // http://localhost is fake address. The HttpHandler will be used to + // open a socket to the named pipe. _channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions { Credentials = ChannelCredentials.Insecure, HttpHandler = socketsHttpHandler, }); + + Daemon = new Daemon.DaemonClient(_channel); Synchronization = new Synchronization.SynchronizationClient(_channel); }