| 1 |
use std::cell::OnceCell; |
| 2 |
|
| 3 |
use cxx::UniquePtr; |
| 4 |
|
| 5 |
use crate::raw::{IndexFile, PkgFileIterator, VerFileIterator}; |
| 6 |
use crate::{Cache, PackageRecords}; |
| 7 |
|
| 8 |
/// Associates a version with a PackageFile |
| 9 |
/// |
| 10 |
/// This allows a full description of all Versions in all files |
| 11 |
pub struct VersionFile<'a> { |
| 12 |
pub(crate) ptr: UniquePtr<VerFileIterator>, |
| 13 |
cache: &'a Cache, |
| 14 |
} |
| 15 |
|
| 16 |
impl<'a> VersionFile<'a> { |
| 17 |
pub fn new(ptr: UniquePtr<VerFileIterator>, cache: &'a Cache) -> VersionFile<'a> { |
| 18 |
VersionFile { ptr, cache } |
| 19 |
} |
| 20 |
|
| 21 |
/// Return the PkgRecords Parser for the VersionFile |
| 22 |
pub fn lookup(&self) -> &PackageRecords { self.cache.records().ver_lookup(&self.ptr) } |
| 23 |
|
| 24 |
/// Return the PackageFile for this VersionFile |
| 25 |
pub fn package_file(&self) -> PackageFile<'a> { |
| 26 |
PackageFile::new(unsafe { self.ptr.package_file() }, self.cache) |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/// Stores information about the files used to generate the cache |
| 31 |
/// |
| 32 |
/// Package files are referenced by Version structures to be able to know |
| 33 |
/// after which Packages file includes this Version. |
| 34 |
pub struct PackageFile<'a> { |
| 35 |
pub(crate) ptr: UniquePtr<PkgFileIterator>, |
| 36 |
cache: &'a Cache, |
| 37 |
index: OnceCell<UniquePtr<IndexFile>>, |
| 38 |
} |
| 39 |
|
| 40 |
impl<'a> PackageFile<'a> { |
| 41 |
pub fn new(ptr: UniquePtr<PkgFileIterator>, cache: &'a Cache) -> PackageFile { |
| 42 |
PackageFile { |
| 43 |
ptr, |
| 44 |
cache, |
| 45 |
index: OnceCell::new(), |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
pub fn index_file(&self) -> &IndexFile { |
| 50 |
self.index |
| 51 |
.get_or_init(|| unsafe { self.cache.find_index(self) }) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
cxx_convert_result!( |
| 56 |
PackageFile, |
| 57 |
/// The path to the PackageFile |
| 58 |
filename() -> &str, |
| 59 |
/// The Archive of the PackageFile. ex: unstable |
| 60 |
archive() -> &str, |
| 61 |
/// The Origin of the PackageFile. ex: Debian |
| 62 |
origin() -> &str, |
| 63 |
/// The Codename of the PackageFile. ex: main, non-free |
| 64 |
codename() -> &str, |
| 65 |
/// The Label of the PackageFile. ex: Debian |
| 66 |
label() -> &str, |
| 67 |
/// The Hostname of the PackageFile. ex: deb.debian.org |
| 68 |
site() -> &str, |
| 69 |
/// The Component of the PackageFile. ex: sid |
| 70 |
component() -> &str, |
| 71 |
/// The Architecture of the PackageFile. ex: amd64 |
| 72 |
arch() -> &str, |
| 73 |
/// The Index Type of the PackageFile. Known values are: |
| 74 |
/// |
| 75 |
/// Debian Package Index, Debian Translation Index |
| 76 |
/// and Debian dpkg status file, |
| 77 |
index_type() -> &str, |
| 78 |
); |
| 79 |
|
| 80 |
#[cxx::bridge] |
| 81 |
pub(crate) mod raw { |
| 82 |
unsafe extern "C++" { |
| 83 |
include!("rust-apt/apt-pkg-c/package.h"); |
| 84 |
|
| 85 |
type VerFileIterator; |
| 86 |
type DescIterator; |
| 87 |
type PkgFileIterator; |
| 88 |
|
| 89 |
/// The path to the PackageFile |
| 90 |
pub fn filename(self: &PkgFileIterator) -> Result<&str>; |
| 91 |
|
| 92 |
/// The Archive of the PackageFile. ex: unstable |
| 93 |
pub fn archive(self: &PkgFileIterator) -> Result<&str>; |
| 94 |
|
| 95 |
/// The Origin of the PackageFile. ex: Debian |
| 96 |
pub fn origin(self: &PkgFileIterator) -> Result<&str>; |
| 97 |
|
| 98 |
/// The Codename of the PackageFile. ex: main, non-free |
| 99 |
pub fn codename(self: &PkgFileIterator) -> Result<&str>; |
| 100 |
|
| 101 |
/// The Label of the PackageFile. ex: Debian |
| 102 |
pub fn label(self: &PkgFileIterator) -> Result<&str>; |
| 103 |
|
| 104 |
/// The Hostname of the PackageFile. ex: deb.debian.org |
| 105 |
pub fn site(self: &PkgFileIterator) -> Result<&str>; |
| 106 |
|
| 107 |
/// The Component of the PackageFile. ex: sid |
| 108 |
pub fn component(self: &PkgFileIterator) -> Result<&str>; |
| 109 |
|
| 110 |
/// The Architecture of the PackageFile. ex: amd64 |
| 111 |
pub fn arch(self: &PkgFileIterator) -> Result<&str>; |
| 112 |
|
| 113 |
/// The Index Type of the PackageFile. Known values are: |
| 114 |
/// |
| 115 |
/// Debian Package Index, Debian Translation Index, Debian dpkg status |
| 116 |
/// file, |
| 117 |
pub fn index_type(self: &PkgFileIterator) -> Result<&str>; |
| 118 |
|
| 119 |
/// `true` if the PackageFile contains packages that can be downloaded |
| 120 |
pub fn is_downloadable(self: &PkgFileIterator) -> bool; |
| 121 |
|
| 122 |
/// The Index number of the PackageFile |
| •123 |
pub fn index(self: &PkgFileIterator) -> usize; |
| 124 |
/// Clone the pointer. |
| 125 |
/// |
| 126 |
/// # Safety |
| 127 |
/// |
| 128 |
/// If the inner pointer is null segfaults can occur. |
| 129 |
/// |
| 130 |
/// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option |
| 131 |
/// is recommended. |
| 132 |
/// |
| 133 |
/// The returned UniquePtr cannot outlive the cache. |
| 134 |
unsafe fn unique(self: &PkgFileIterator) -> UniquePtr<PkgFileIterator>; |
| 135 |
pub fn raw_next(self: Pin<&mut PkgFileIterator>); |
| 136 |
pub fn end(self: &PkgFileIterator) -> bool; |
| 137 |
|
| 138 |
/// Return the package file associated with this version file. |
| 139 |
/// |
| 140 |
/// # Safety |
| 141 |
/// |
| 142 |
/// If the inner pointer is null segfaults can occur. |
| 143 |
/// |
| 144 |
/// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option |
| 145 |
/// is recommended. |
| 146 |
/// |
| 147 |
/// The returned UniquePtr cannot outlive the cache. |
| 148 |
unsafe fn package_file(self: &VerFileIterator) -> UniquePtr<PkgFileIterator>; |
| 149 |
|
| •150 |
pub fn index(self: &VerFileIterator) -> usize; |
| 151 |
/// Clone the pointer. |
| 152 |
/// |
| 153 |
/// # Safety |
| 154 |
/// |
| 155 |
/// If the inner pointer is null segfaults can occur. |
| 156 |
/// |
| 157 |
/// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option |
| 158 |
/// is recommended. |
| 159 |
/// |
| 160 |
/// The returned UniquePtr cannot outlive the cache. |
| 161 |
unsafe fn unique(self: &VerFileIterator) -> UniquePtr<VerFileIterator>; |
| 162 |
pub fn raw_next(self: Pin<&mut VerFileIterator>); |
| 163 |
pub fn end(self: &VerFileIterator) -> bool; |
| 164 |
|
| •165 |
pub fn index(self: &DescIterator) -> usize; |
| 166 |
/// Clone the pointer. |
| 167 |
/// |
| 168 |
/// # Safety |
| 169 |
/// |
| 170 |
/// If the inner pointer is null segfaults can occur. |
| 171 |
/// |
| 172 |
/// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option |
| 173 |
/// is recommended. |
| 174 |
/// |
| 175 |
/// The returned UniquePtr cannot outlive the cache. |
| 176 |
unsafe fn unique(self: &DescIterator) -> UniquePtr<DescIterator>; |
| 177 |
pub fn raw_next(self: Pin<&mut DescIterator>); |
| 178 |
pub fn end(self: &DescIterator) -> bool; |
| 179 |
} |
| 180 |
} |