mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-03-28 18:24:19 -04:00
fixed: Loading native libraries on FreeBSD and Linux
This commit is contained in:
@@ -14,7 +14,6 @@ namespace NzbDrone.Common.Composition
|
||||
static AssemblyLoader()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ContainerResolveEventHandler);
|
||||
RegisterSQLiteResolver();
|
||||
}
|
||||
|
||||
public static IList<Assembly> Load(IList<string> assemblyNames)
|
||||
@@ -23,6 +22,10 @@ namespace NzbDrone.Common.Composition
|
||||
toLoad.Add("Prowlarr.Common");
|
||||
toLoad.Add(OsInfo.IsWindows ? "Prowlarr.Windows" : "Prowlarr.Mono");
|
||||
|
||||
var toRegisterResolver = new List<string> { "System.Data.SQLite" };
|
||||
toRegisterResolver.AddRange(assemblyNames.Intersect(new[] { "Prowlarr.Core" }));
|
||||
RegisterNativeResolver(toRegisterResolver);
|
||||
|
||||
var startupPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
return toLoad
|
||||
@@ -43,25 +46,28 @@ namespace NzbDrone.Common.Composition
|
||||
return AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||
}
|
||||
|
||||
public static void RegisterSQLiteResolver()
|
||||
public static void RegisterNativeResolver(IEnumerable<string> assemblyNames)
|
||||
{
|
||||
// This ensures we look for sqlite3 using libsqlite3.so.0 on Linux and not libsqlite3.so which
|
||||
// is less likely to exist.
|
||||
var sqliteAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(
|
||||
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System.Data.SQLite.dll"));
|
||||
foreach (var name in assemblyNames)
|
||||
{
|
||||
// This ensures we look for sqlite3 using libsqlite3.so.0 on Linux and not libsqlite3.so which
|
||||
// is less likely to exist.
|
||||
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(
|
||||
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{name}.dll"));
|
||||
|
||||
try
|
||||
{
|
||||
NativeLibrary.SetDllImportResolver(sqliteAssembly, LoadSqliteNativeLib);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// This can only be set once per assembly
|
||||
// Catch required for NzbDrone.Host tests
|
||||
try
|
||||
{
|
||||
NativeLibrary.SetDllImportResolver(assembly, LoadNativeLib);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// This can only be set once per assembly
|
||||
// Catch required for NzbDrone.Host tests
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr LoadSqliteNativeLib(string libraryName, Assembly assembly, DllImportSearchPath? dllImportSearchPath)
|
||||
private static IntPtr LoadNativeLib(string libraryName, Assembly assembly, DllImportSearchPath? dllImportSearchPath)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(libraryName);
|
||||
|
||||
|
||||
@@ -22,15 +22,6 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||
return expressionRoot.Table(name).WithColumn("Id").AsInt32().PrimaryKey().Identity();
|
||||
}
|
||||
|
||||
public static IDbCommand CreateCommand(this IDbConnection conn, IDbTransaction tran, string query)
|
||||
{
|
||||
var command = conn.CreateCommand();
|
||||
command.Transaction = tran;
|
||||
command.CommandText = query;
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
public static void AddParameter(this IDbCommand command, object value)
|
||||
{
|
||||
var parameter = command.CreateParameter();
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace NzbDrone.Test.Common.AutoMoq
|
||||
|
||||
if (behavior != MockBehavior.Default && mock.Behavior == MockBehavior.Default)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to change be behaviour of a an existing mock.");
|
||||
throw new InvalidOperationException("Unable to change be behaviour of an existing mock.");
|
||||
}
|
||||
|
||||
return mock;
|
||||
@@ -139,7 +139,7 @@ namespace NzbDrone.Test.Common.AutoMoq
|
||||
|
||||
LoadPlatformLibrary();
|
||||
|
||||
AssemblyLoader.RegisterSQLiteResolver();
|
||||
AssemblyLoader.RegisterNativeResolver(new[] { "System.Data.SQLite", "Prowlarr.Core" });
|
||||
}
|
||||
|
||||
private Mock<T> TheRegisteredMockForThisType<T>(Type type)
|
||||
|
||||
Reference in New Issue
Block a user