checkpoint for real

This commit is contained in:
2020-04-27 12:34:56 -04:00
parent 6ed92261ec
commit c1618deb83
31 changed files with 1429 additions and 626 deletions

52
SafeCachePackageHandle.cs Normal file
View File

@@ -0,0 +1,52 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
namespace Foodsoft.Alpm
{
internal sealed class SafeCachePackageHandle : SafePackageHandle
{
internal SafeDatabaseHandle SafeDatabaseHandle
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[PrePrepareMethod]
get;
} = null!;
internal SafeAlpmHandle SafeAlpmHandle => SafeDatabaseHandle.SafeAlpmHandle;
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
[PrePrepareMethod]
internal SafeCachePackageHandle(IntPtr pkgPtr, SafeDatabaseHandle dbHandle)
: base()
{
var success = false;
RuntimeHelpers.PrepareConstrainedRegions();
try { }
finally
{
dbHandle.DangerousAddRef(ref success);
if (success)
{
handle = pkgPtr;
SafeDatabaseHandle = dbHandle;
}
}
if (!success) throw new ObjectDisposedException(GetType().FullName);
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), PrePrepareMethod]
protected override bool ReleaseHandle()
{
SafeDatabaseHandle.DangerousRelease();
return true;
}
public override bool IsInvalid
{
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), PrePrepareMethod]
get => handle == IntPtr.Zero;
}
}
}