checkpoint

This commit is contained in:
2020-04-30 20:40:52 -04:00
parent 9aa367e9f5
commit abba062f4f
28 changed files with 615 additions and 544 deletions

View File

@@ -1,20 +1,25 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Foodsoft.Alpm
{
public sealed class Handle : IDisposable
{
private readonly SafeAlpmHandle _handle;
public Handle(string root, string dbpath)
{
_handle = alpm.alpm_initialize(root, dbpath, out var err);
if (_handle.IsInvalid)
{
throw new AlpmException(err);
}
if (_handle.IsInvalid) throw new AlpmException(err);
}
public Database LocalDB => ToDatabase(alpm.alpm_get_localdb(_handle));
public ICollection<string> CacheDirs
{
get =>
EnumerableWrapper.Create(_handle, alpm.alpm_option_get_cachedirs);
set => Detail.SetStringCollection(value, _handle, s => alpm.alpm_option_add_cachedir(_handle, s));
}
public void Dispose()
@@ -26,28 +31,29 @@ namespace Foodsoft.Alpm
{
// It's ok that the database pointer is kept outside atomic section, because the resource is actually
// managed by the alpm handle.
if (ptr == IntPtr.Zero)
{
throw new AlpmException(_handle);
}
if (ptr == IntPtr.Zero) throw new AlpmException(_handle);
return new Database(new SafeDatabaseHandle(ptr, _handle));
}
public Database LocalDB => ToDatabase(alpm.alpm_get_localdb(_handle));
public Database RegisterSyncDB(string treename, SigLevel sigLevel = 0) =>
ToDatabase(alpm.alpm_register_syncdb(_handle, treename, sigLevel));
public void AddCacheDir(string dir) => Detail.WrapError(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
public bool RemoveCacheDir(string dir) => Detail.WrapErrorBool(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
public ICollection<string> CacheDirs
public Database RegisterSyncDB(string treename, SigLevel sigLevel = 0)
{
get =>
EnumerableWrapper.Create(_handle, alpm.alpm_option_get_cachedirs);
set => Detail.SetStringCollection(value, _handle, (s) => alpm.alpm_option_add_cachedir(_handle, s));
return ToDatabase(alpm.alpm_register_syncdb(_handle, treename, sigLevel));
}
public bool ShouldIgnorePackage(Package pkg) => alpm.alpm_pkg_should_ignore(_handle, pkg.Handle) == 0;
public void AddCacheDir(string dir)
{
Detail.WrapError(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
}
public bool RemoveCacheDir(string dir)
{
return Detail.WrapErrorBool(_handle, () => alpm.alpm_option_add_cachedir(_handle, dir));
}
public bool ShouldIgnorePackage(Package pkg)
{
return alpm.alpm_pkg_should_ignore(_handle, pkg.Handle) == 0;
}
}
}