Skip to content

Commit

Permalink
Boostrap: Apply --0install-version= to already deployed instances on …
Browse files Browse the repository at this point in the history
…integrate
  • Loading branch information
bastianeicher committed Jul 25, 2024
1 parent 03f5fbd commit e127384
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Bootstrap/BootstrapProcess.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Bastian Eicher et al.
// Licensed under the GNU Lesser Public License

using System.Diagnostics;
using NanoByte.Common.Native;
using ZeroInstall.Services;
using ZeroInstall.Store.Configuration;
Expand Down Expand Up @@ -75,6 +76,9 @@ private ExitCode ExecuteIntegrate()
if (_machineWide) args.Add("--machine");
args.Add(WindowsUtils.SplitArgs(_integrateArgs ?? integrateArgs));

if (ZeroInstallDeployment.FindOther(_machineWide) is {} deployedInstance)
EnsureRequestedZeroInstallVersion(deployedInstance);

var startInfo = ZeroInstall(args);
return _handler.RunTaskAndReturn(ResultTask.Create(
$"Integrating {BootstrapConfig.Instance.AppName}",
Expand All @@ -84,6 +88,25 @@ private ExitCode ExecuteIntegrate()
return ExitCode.OK;
}

/// <summary>
/// Checks if a deployed instance of Zero Install matches the requested <see cref="_version"/> and updates it if not.
/// </summary>
private void EnsureRequestedZeroInstallVersion(string path)
{
if (_version == null) return;

string versionFile = Path.Combine(path, "0install.exe");
if (!File.Exists(versionFile)) return;

var deployedVersion = new ImplementationVersion(FileVersionInfo.GetVersionInfo(versionFile).ProductVersion.GetLeftPartAtFirstOccurrence('+'));
if (!_version.Match(deployedVersion))
{
Log.Info($"Zero Install instance deployed at {path} has version {deployedVersion} that does not match desired version {_version}");
var startInfo = ZeroInstallCached(["self", "deploy", "--batch", path]);
_handler.RunTask(new ActionTask("Updating Zero Install", () => startInfo.Run()));
}
}

/// <summary>
/// Runs <c>0install</c> with <c>run</c>, <c>central</c> or other user-provided arguments.
/// </summary>
Expand Down

0 comments on commit e127384

Please sign in to comment.