Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
This commit introduces the OpenSslLegacyShim class, which sets the LD_LIBRARY_PATH environment variable to include the directory containing OpenSSL 1.1 native libraries. This is necessary for Mongo2Go to function correctly on Linux platforms that do not ship these libraries by default. The shim checks if the current operating system is Linux and whether the required directory exists before modifying the environment variable.
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace StellaOps.Testing;
|
|
|
|
/// <summary>
|
|
/// Ensures OpenSSL 1.1 native libraries are visible to Mongo2Go on platforms that no longer ship them.
|
|
/// </summary>
|
|
public static class OpenSslLegacyShim
|
|
{
|
|
private const string LinuxLibraryVariable = "LD_LIBRARY_PATH";
|
|
|
|
public static void EnsureOpenSsl11()
|
|
{
|
|
if (!OperatingSystem.IsLinux())
|
|
{
|
|
return;
|
|
}
|
|
|
|
var nativeDirectory = Path.Combine(AppContext.BaseDirectory, "native", "linux-x64");
|
|
if (!Directory.Exists(nativeDirectory))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var current = Environment.GetEnvironmentVariable(LinuxLibraryVariable);
|
|
if (string.IsNullOrEmpty(current))
|
|
{
|
|
Environment.SetEnvironmentVariable(LinuxLibraryVariable, nativeDirectory);
|
|
return;
|
|
}
|
|
|
|
const char separator = ':';
|
|
var segments = current.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
|
if (segments.Contains(nativeDirectory, StringComparer.Ordinal))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Environment.SetEnvironmentVariable(LinuxLibraryVariable, string.Concat(nativeDirectory, separator, current));
|
|
}
|
|
}
|