oma_apt/
pkgmanager.rs

1//! Contains types and bindings for fetching and installing packages from the
2//! cache.
3
4#[cxx::bridge]
5pub(crate) mod raw {
6    #[repr(u32)]
7    enum OrderResult {
8        Completed,
9        Failed,
10        Incomplete,
11    }
12
13    unsafe extern "C++" {
14        include!("oma-apt/apt-pkg-c/pkgmanager.h");
15
16        type PackageManager;
17        type ProblemResolver;
18        type OrderResult;
19
20        type PkgCacheFile = crate::cache::raw::PkgCacheFile;
21        type PkgIterator = crate::cache::raw::PkgIterator;
22        type PkgRecords = crate::records::raw::PkgRecords;
23        type PkgDepCache = crate::depcache::raw::PkgDepCache;
24        type AcqTextStatus = crate::acquire::raw::AcqTextStatus;
25
26        type InstallProgressFancy<'a> = crate::progress::InstallProgressFancy<'a>;
27        type OperationProgress<'a> = crate::progress::OperationProgress<'a>;
28
29        /// # Safety
30        ///
31        /// The returned UniquePtr cannot outlive the cache.
32        unsafe fn create_pkgmanager(depcache: &PkgDepCache) -> UniquePtr<PackageManager>;
33
34        pub fn get_archives(
35            self: &PackageManager,
36            cache: &PkgCacheFile,
37            records: &PkgRecords,
38            progress: Pin<&mut AcqTextStatus>,
39        ) -> Result<()>;
40
41        pub fn do_install(
42            self: &PackageManager,
43            progress: Pin<&mut InstallProgressFancy>,
44        ) -> OrderResult;
45
46        /// Send dpkg status messages to an File Descriptor.
47        /// This required more work to implement but is the most flexible.
48        pub fn do_install_fd(self: &PackageManager, fd: i32) -> OrderResult;
49
50        /// # Safety
51        ///
52        /// The returned UniquePtr cannot outlive the cache.
53        unsafe fn create_problem_resolver(depcache: &PkgDepCache) -> UniquePtr<ProblemResolver>;
54
55        pub fn clear(self: &ProblemResolver, pkg: &PkgIterator);
56        pub fn protect(self: &ProblemResolver, pkg: &PkgIterator);
57
58        fn resolve(
59            self: &ProblemResolver,
60            fix_broken: bool,
61            op_progress: Pin<&mut OperationProgress>,
62        ) -> Result<()>;
63    }
64}