Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to properly support Mutexes on NET6.0 #2206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions LiteDB/Client/Shared/SharedEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using System.Security.AccessControl;
using System.Security.Principal;
#endif
Expand All @@ -27,16 +27,33 @@ public SharedEngine(EngineSettings settings)

try
{
#if NETFRAMEWORK
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
if (!OperatingSystem.IsWindows())
_mutex = new Mutex(false, "Global\\" + name + ".Mutex");
else
{
#endif
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
MutexRights.FullControl, AccessControlType.Allow);

var securitySettings = new MutexSecurity();
securitySettings.AddAccessRule(allowEveryoneRule);

var securitySettings = new MutexSecurity();
securitySettings.AddAccessRule(allowEveryoneRule);
#if NET6_0_OR_GREATER
_mutex = MutexAcl.Create(false, "Global\\" + name + ".Mutex", out _, securitySettings);
#endif
#if NETFRAMEWORK
_mutex = new Mutex(false, "Global\\" + name + ".Mutex", out _, securitySettings);
#endif
#if NETSTANDARD2_0_OR_GREATER
_mutex = new Mutex(false, "Global\\" + name + ".Mutex");
ThreadingAclExtensions.SetAccessControl(_mutex, securitySettings);
#endif
#else
_mutex = new Mutex(false, "Global\\" + name + ".Mutex");
#endif
#if NET6_0_OR_GREATER
}
#endif
}
catch (NotSupportedException ex)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big nope! Please make it more readable.

Expand Down Expand Up @@ -95,7 +112,7 @@ private void CloseDatabase()
}
}

#region Transaction Operations
#region Transaction Operations

public bool BeginTrans()
{
Expand Down Expand Up @@ -147,9 +164,9 @@ public bool Rollback()
}
}

#endregion
#endregion

#region Read Operation
#region Read Operation

public IBsonDataReader Query(string collection, Query query)
{
Expand Down Expand Up @@ -188,9 +205,9 @@ public bool Pragma(string name, BsonValue value)
}
}

#endregion
#endregion

#region Write Operations
#region Write Operations

public int Checkpoint()
{
Expand Down Expand Up @@ -360,7 +377,7 @@ public bool EnsureIndex(string collection, string name, BsonExpression expressio
}
}

#endregion
#endregion

public void Dispose()
{
Expand Down
21 changes: 13 additions & 8 deletions LiteDB/LiteDB.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyVersion>5.0.12</AssemblyVersion>
<FileVersion>5.0.12</FileVersion>
<VersionPrefix>5.0.12</VersionPrefix>
<TargetFrameworks>netstandard1.3;netstandard2.0;net6.0</TargetFrameworks>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not going to add or drop support for any TargetFrameworks just yet ;)

<AssemblyVersion>5.0.14</AssemblyVersion>
<FileVersion>5.0.14</FileVersion>
<VersionPrefix>5.0.14</VersionPrefix>
<Authors>Maurício David</Authors>
<Product>LiteDB</Product>
<Description>LiteDB - A lightweight embedded .NET NoSQL document store in a single datafile</Description>
<Copyright>MIT</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<Title>LiteDB</Title>
<PackageId>LiteDB</PackageId>
<PackageVersion>5.0.12</PackageVersion>
<PackageVersion>5.0.14</PackageVersion>
<PackageTags>database nosql embedded</PackageTags>
<PackageIcon>icon_64x64.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand All @@ -25,9 +25,8 @@
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.1</NetStandardImplicitPackageVersion>
<NoWarn>1701;1702;1705;1591;0618</NoWarn>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\LiteDB.xml</DocumentationFile>
<SignAssembly Condition="'$(OS)'=='Windows_NT'">true</SignAssembly>
<AssemblyOriginatorKeyFile Condition="'$(Configuration)' == 'Release'">LiteDB.snk</AssemblyOriginatorKeyFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>True</SignAssembly>
</PropertyGroup>

<!--
Expand Down Expand Up @@ -65,7 +64,13 @@
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.5.1" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Threading.AccessControl" Version="4.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Threading.AccessControl" Version="6.0.0" />
</ItemGroup>

<!-- End References -->

</Project>