1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! oma-apt provides bindings to `libapt-pkg`.
//! The goal is to eventually have all of the functionality of `python-apt`
//!
//! The source repository is <https://gitlab.com/volian/oma-apt>
//! For more information please see the readme in the source code.
//!
//! Each module has a `raw` submodule containing c++ bindings to `libapt-pkg`
//!
//! These are safe to use in terms of memory,
//! but may cause segfaults if you do something wrong.
//!
//! If you find a way to segfault without using the `libapt-pkg` bindings
//! directly, please report this as a bug.

// Clippy is really mad at my safety docs and idk why
#![allow(clippy::missing_safety_doc)]

#[macro_use]
mod macros;
mod acquire;
pub mod cache;
pub mod config;
mod depcache;
pub mod error;
mod iterators;
mod pkgmanager;
pub mod progress;
pub mod records;
pub mod tagfile;
pub mod util;

#[doc(inline)]
pub use cache::{Cache, PackageSort};
pub use iterators::dependency::{create_depends_map, BaseDep, DepFlags, DepType, Dependency};
pub use iterators::files::{PackageFile, VersionFile};
pub use iterators::package::{Package, PkgCurrentState, PkgInstState, PkgSelectedState};
pub use iterators::provider::Provider;
pub use iterators::version::Version;

/// C++ bindings for libapt-pkg
pub mod raw {
	pub use crate::acquire::raw::{
		acquire_status, create_acquire, AcqTextStatus, AcqWorker, Item, ItemDesc, ItemState,
		PkgAcquire,
	};
	pub use crate::cache::raw::{create_cache, PkgCacheFile};
	pub use crate::depcache::raw::{ActionGroup, PkgDepCache};
	pub use crate::iterators::{
		DepIterator, DescIterator, PkgFileIterator, PkgIterator, PrvIterator, VerFileIterator,
		VerIterator,
	};
	pub use crate::pkgmanager::raw::{
		create_pkgmanager, create_problem_resolver, PackageManager, ProblemResolver,
	};
	pub use crate::records::raw::{IndexFile, Parser, PkgRecords};
	pub use crate::util::raw::*;
	// Hmm, maybe this is reason enough to make a wrapper in C++
	// So that the raw functions are methods on a "Config" struct?
	// But it may need to not outlive the cache if we do that.
	pub mod config {
		pub use crate::config::raw::*;
	}

	/// Iterator trait for libapt raw bindings
	pub trait IntoRawIter {
		type Item;
		fn raw_iter(self) -> Self::Item;

		fn make_safe(self) -> Option<Self>
		where
			Self: Sized;

		fn to_vec(self) -> Vec<Self>
		where
			Self: Sized;
	}

	use cxx::UniquePtr;
	use paste::paste;

	raw_iter!(
		PkgIterator,
		VerIterator,
		DepIterator,
		PrvIterator,
		VerFileIterator,
		DescIterator,
		PkgFileIterator
	);
}

use depcache::DepCache;
use error::AptErrors;
use records::PackageRecords;

impl_deref!(
	Cache -> raw::PkgCacheFile,
	DepCache -> raw::PkgDepCache,
	PackageRecords -> raw::PkgRecords,
	AptErrors -> Vec<error::raw::AptError>,
	Package<'a> -> raw::PkgIterator,
	Version<'a> -> raw::VerIterator,
	Dependency<'a> -> Vec<BaseDep<'a>>,
	BaseDep<'a> -> raw::DepIterator,
	Provider<'a> -> raw::PrvIterator,
	VersionFile<'a> -> raw::VerFileIterator,
	PackageFile<'a> -> raw::PkgFileIterator,
);

// Version is omitted because it has special needs
impl_partial_eq!(
	Package<'a>,
	BaseDep<'a>,
	Provider<'a>,
	VersionFile<'a>,
	PackageFile<'a>,
);

impl_hash_eq!(
	Package<'a>,
	Version<'a>,
	BaseDep<'a>,
	Provider<'a>,
	VersionFile<'a>,
	PackageFile<'a>,
);