46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.ConstrainedExecution;
|
|
|
|
namespace Foodsoft.Alpm
|
|
{
|
|
internal sealed class SafeCachePackageHandle : SafePackageHandle
|
|
{
|
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
|
[PrePrepareMethod]
|
|
internal SafeCachePackageHandle(IntPtr ptr, SafeDatabaseHandle parentHandle)
|
|
: base(parentHandle.SafeAlpmHandle)
|
|
{
|
|
var success = false;
|
|
|
|
RuntimeHelpers.PrepareConstrainedRegions();
|
|
try { }
|
|
finally
|
|
{
|
|
parentHandle.DangerousAddRef(ref success);
|
|
if (success)
|
|
{
|
|
SafeDatabaseHandle = parentHandle;
|
|
handle = ptr;
|
|
}
|
|
}
|
|
|
|
if (!success) throw new ObjectDisposedException(GetType().FullName);
|
|
}
|
|
|
|
internal SafeDatabaseHandle SafeDatabaseHandle
|
|
{
|
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
|
[PrePrepareMethod]
|
|
get;
|
|
} = null!;
|
|
|
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
|
[PrePrepareMethod]
|
|
protected override bool ReleaseHandle()
|
|
{
|
|
SafeDatabaseHandle.DangerousRelease();
|
|
return true;
|
|
}
|
|
}
|
|
} |