Debian Codegraph @

src/iterators/files.rs

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 #[cxx_name = "Index"]
124 pub fn index(self: &PkgFileIterator) -> u64;
125 /// Clone the pointer.
126 ///
127 /// # Safety
128 ///
129 /// If the inner pointer is null segfaults can occur.
130 ///
131 /// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option
132 /// is recommended.
133 ///
134 /// The returned UniquePtr cannot outlive the cache.
135 unsafe fn unique(self: &PkgFileIterator) -> UniquePtr<PkgFileIterator>;
136 pub fn raw_next(self: Pin<&mut PkgFileIterator>);
137 pub fn end(self: &PkgFileIterator) -> bool;
138
139 /// Return the package file associated with this version file.
140 ///
141 /// # Safety
142 ///
143 /// If the inner pointer is null segfaults can occur.
144 ///
145 /// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option
146 /// is recommended.
147 ///
148 /// The returned UniquePtr cannot outlive the cache.
149 unsafe fn package_file(self: &VerFileIterator) -> UniquePtr<PkgFileIterator>;
150
151 #[cxx_name = "Index"]
152 pub fn index(self: &VerFileIterator) -> u64;
153 /// Clone the pointer.
154 ///
155 /// # Safety
156 ///
157 /// If the inner pointer is null segfaults can occur.
158 ///
159 /// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option
160 /// is recommended.
161 ///
162 /// The returned UniquePtr cannot outlive the cache.
163 unsafe fn unique(self: &VerFileIterator) -> UniquePtr<VerFileIterator>;
164 pub fn raw_next(self: Pin<&mut VerFileIterator>);
165 pub fn end(self: &VerFileIterator) -> bool;
166
167 #[cxx_name = "Index"]
168 pub fn index(self: &DescIterator) -> u64;
169 /// Clone the pointer.
170 ///
171 /// # Safety
172 ///
173 /// If the inner pointer is null segfaults can occur.
174 ///
175 /// Using [`crate::raw::IntoRawIter::make_safe`] to convert to an Option
176 /// is recommended.
177 ///
178 /// The returned UniquePtr cannot outlive the cache.
179 unsafe fn unique(self: &DescIterator) -> UniquePtr<DescIterator>;
180 pub fn raw_next(self: Pin<&mut DescIterator>);
181 pub fn end(self: &DescIterator) -> bool;
182 }
183 }