checkpoint
This commit is contained in:
39
Alpm/SafeFilePackageHandle.cs
Normal file
39
Alpm/SafeFilePackageHandle.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Foodsoft.Alpm
|
||||
{
|
||||
internal class SafeFilePackageHandle : SafePackageHandle
|
||||
{
|
||||
internal SafeAlpmHandle SafeAlpmHandle { get; } = null!;
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[PrePrepareMethod]
|
||||
internal SafeFilePackageHandle(IntPtr ptr, SafeAlpmHandle parentHandle)
|
||||
{
|
||||
var success = false;
|
||||
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try { }
|
||||
finally
|
||||
{
|
||||
parentHandle.DangerousAddRef(ref success);
|
||||
if (success)
|
||||
{
|
||||
SafeAlpmHandle = parentHandle;
|
||||
handle = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) throw new ObjectDisposedException(GetType().FullName);
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
SafeAlpmHandle.DangerousRelease();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user