mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-05-07 12:10:20 +02:00
fixed: Loading native libraries on FreeBSD and Linux
This commit is contained in:
parent
5edde8d9bd
commit
b0e879da5c
3 changed files with 23 additions and 26 deletions
|
|
@ -14,7 +14,6 @@ public class AssemblyLoader
|
|||
static AssemblyLoader()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ContainerResolveEventHandler);
|
||||
RegisterSQLiteResolver();
|
||||
}
|
||||
|
||||
public static IList<Assembly> Load(IList<string> assemblyNames)
|
||||
|
|
@ -23,6 +22,10 @@ public static IList<Assembly> Load(IList<string> assemblyNames)
|
|||
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 @@ private static Assembly ContainerResolveEventHandler(object sender, ResolveEvent
|
|||
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 @@ public static ICreateTableColumnOptionOrWithColumnSyntax TableForModel(this ICre
|
|||
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 @@ public virtual Mock<T> GetMock<T>(MockBehavior behavior)
|
|||
|
||||
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 @@ private void SetupAutoMoqer(IContainer container)
|
|||
|
||||
LoadPlatformLibrary();
|
||||
|
||||
AssemblyLoader.RegisterSQLiteResolver();
|
||||
AssemblyLoader.RegisterNativeResolver(new[] { "System.Data.SQLite", "Prowlarr.Core" });
|
||||
}
|
||||
|
||||
private Mock<T> TheRegisteredMockForThisType<T>(Type type)
|
||||
|
|
|
|||
Loading…
Reference in a new issue