use cxx::UniquePtr;
use crate::error::AptErrors;
use crate::progress::OperationProgress;
use crate::raw::PkgDepCache;
use crate::util::DiskSpace;
pub struct DepCache {
pub(crate) ptr: UniquePtr<PkgDepCache>,
}
impl DepCache {
pub fn new(ptr: UniquePtr<PkgDepCache>) -> DepCache { DepCache { ptr } }
pub fn clear_marked(&self) -> Result<(), AptErrors> {
Ok(self.init(OperationProgress::quiet().pin().as_mut())?)
}
pub fn disk_size(&self) -> DiskSpace {
let size = self.ptr.disk_size();
if size < 0 {
return DiskSpace::Free(-size as u64);
}
DiskSpace::Require(size as u64)
}
}
#[cxx::bridge]
pub(crate) mod raw {
impl UniquePtr<PkgDepCache> {}
unsafe extern "C++" {
include!("rust-apt/apt-pkg-c/depcache.h");
type PkgDepCache;
type ActionGroup;
type PkgIterator = crate::iterators::PkgIterator;
type VerIterator = crate::iterators::VerIterator;
type DepIterator = crate::iterators::DepIterator;
type OperationProgress<'a> = crate::progress::OperationProgress<'a>;
pub fn init(self: &PkgDepCache, callback: Pin<&mut OperationProgress>) -> Result<()>;
pub fn fix_broken(self: &PkgDepCache) -> bool;
unsafe fn action_group(self: &PkgDepCache) -> UniquePtr<ActionGroup>;
pub fn release(self: Pin<&mut ActionGroup>);
pub fn upgrade(
self: &PkgDepCache,
progress: Pin<&mut OperationProgress>,
upgrade_mode: i32,
) -> Result<()>;
pub fn is_upgradable(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn is_auto_installed(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn is_garbage(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_new_install(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_install(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_upgrade(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_purge(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_delete(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_held(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_keep(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_downgrade(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn marked_reinstall(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn mark_auto(self: &PkgDepCache, pkg: &PkgIterator, mark_auto: bool);
pub fn mark_keep(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn mark_delete(self: &PkgDepCache, pkg: &PkgIterator, purge: bool) -> bool;
pub fn mark_install(
self: &PkgDepCache,
pkg: &PkgIterator,
auto_inst: bool,
from_user: bool,
) -> bool;
pub fn set_candidate_version(self: &PkgDepCache, ver: &VerIterator);
unsafe fn candidate_version(
self: &PkgDepCache,
pkg: &PkgIterator,
) -> UniquePtr<VerIterator>;
unsafe fn install_version(self: &PkgDepCache, pkg: &PkgIterator) -> UniquePtr<VerIterator>;
pub fn dep_state(self: &PkgDepCache, dep: &DepIterator) -> u8;
pub fn is_important_dep(self: &PkgDepCache, dep: &DepIterator) -> bool;
pub fn mark_reinstall(self: &PkgDepCache, pkg: &PkgIterator, reinstall: bool);
pub fn is_now_broken(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn is_inst_broken(self: &PkgDepCache, pkg: &PkgIterator) -> bool;
pub fn install_count(self: &PkgDepCache) -> u32;
pub fn delete_count(self: &PkgDepCache) -> u32;
pub fn keep_count(self: &PkgDepCache) -> u32;
pub fn broken_count(self: &PkgDepCache) -> u32;
pub fn download_size(self: &PkgDepCache) -> u64;
pub fn disk_size(self: &PkgDepCache) -> i64;
}
}