Debian Codegraph @

src/util.rs

raw symbols SCIP
1 //! Contains miscellaneous helper utilities.
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
3
4 use terminal_sizerust-analyzer cargo terminal_size 0.4.4 crate/::{terminal_sizerust-analyzer cargo terminal_size 0.4.4 unix/terminal_size()., Heightrust-analyzer cargo terminal_size 0.4.4 Height#, Widthrust-analyzer cargo terminal_size 0.4.4 Width#};
5
6 use craterust-analyzer cargo rust-apt 0.8.0 crate/::errorrust-analyzer cargo rust-apt 0.8.0 error/::AptErrorsrust-analyzer cargo rust-apt 0.8.0 error/AptErrors#;
7 use craterust-analyzer cargo rust-apt 0.8.0 crate/::{configrust-analyzer cargo rust-apt 0.8.0 config/, Cacherust-analyzer cargo rust-apt 0.8.0 cache/Cache#, DepFlagsrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepFlags/, Packagerust-analyzer cargo rust-apt 0.8.0 iterators/package/Package#};
8
9 /// Get the terminal's height, i.e. the number of rows it has.
10 ///
11 /// # Returns:
12 /// * The terminal height, or `24` if it cannot be determined.
13 pub fn terminal_heightrust-analyzer cargo rust-apt 0.8.0 util/terminal_height().() -> usize {
14 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_, Heightrust-analyzer cargo terminal_size 0.4.4 Height#(rows))) = terminal_sizerust-analyzer cargo terminal_size 0.4.4 unix/terminal_size().() {
15 usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(rows)
16 } else {
17 24
18 }
19 }
20
21 /// Get the terminal's width, i.e. the number of columns it has.
22 ///
23 /// # Returns:
24 /// * The terminal width, or `80` if it cannot be determined.
25 pub fn terminal_widthrust-analyzer cargo rust-apt 0.8.0 util/terminal_width().() -> usize {
26 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((Widthrust-analyzer cargo terminal_size 0.4.4 Width#(cols), _)) = terminal_sizerust-analyzer cargo terminal_size 0.4.4 unix/terminal_size().() {
27 usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(cols)
28 } else {
29 80
30 }
31 }
32
33 /// Compares two package versions, `ver1` and `ver2`. The returned enum variant
34 /// applies to the first version passed in.
35 ///
36 /// # Examples
37 /// ```
38 /// use rust_apt::util::cmp_versions;
39 /// use std::cmp::Ordering;
40 ///
41 /// let ver1 = "5.0";
42 /// let ver2 = "6.0";
43 /// let result = cmp_versions(ver1, ver2);
44 ///
45 /// assert_eq!(Ordering::Less, result);
46 /// ```
47 pub fn cmp_versionsrust-analyzer cargo rust-apt 0.8.0 util/cmp_versions().(ver1: &str, ver2: &str) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
48 let result = rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::cmp_versionsrust-analyzer cargo rust-apt 0.8.0 util/raw/cmp_versions().(ver1, ver2);
49 match result {
50 _ if result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less#,
51 _ if result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#,
52 _ => Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater#,
53 }
54 }
55
56 /// Disk Space that `apt` will use for a transaction.
57 pub enum DiskSpacerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace# {
58 /// Additional Disk Space required.
59 Requirerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace#Require#(u64),
60 /// Disk Space that will be freed
61 Freerust-analyzer cargo rust-apt 0.8.0 util/DiskSpace#Free#(u64),
62 }
63
64 /// Numeral System for unit conversion.
65 pub enum NumSysrust-analyzer cargo rust-apt 0.8.0 util/NumSys# {
66 /// Base 2 | 1024 | KibiByte (KiB)
67 Binaryrust-analyzer cargo rust-apt 0.8.0 util/NumSys#Binary#,
68 /// Base 10 | 1000 | KiloByte (KB)
69 Decimalrust-analyzer cargo rust-apt 0.8.0 util/NumSys#Decimal#,
70 }
71
72 /// Converts bytes into human readable output.
73 ///
74 /// ```
75 /// use rust_apt::new_cache;
76 /// use rust_apt::util::{unit_str, NumSys};
77 /// let cache = new_cache!().unwrap();
78 /// let pkg = cache.get("apt").unwrap();
79 /// let version = pkg.candidate().unwrap();
80 ///
81 /// println!("{}", unit_str(version.size(), NumSys::Decimal));
82 /// ```
83 pub fn unit_strrust-analyzer cargo rust-apt 0.8.0 util/unit_str().(val: u64, base: NumSysrust-analyzer cargo rust-apt 0.8.0 util/NumSys#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
84 let val = val as f64;
85 let (num, tera, giga, mega, kilo) = match base {
86 NumSysrust-analyzer cargo rust-apt 0.8.0 util/NumSys#::Binaryrust-analyzer cargo rust-apt 0.8.0 util/NumSys#Binary# => (1024.0_f64, "TiB", "GiB", "MiB", "KiB"),
87 NumSysrust-analyzer cargo rust-apt 0.8.0 util/NumSys#::Decimalrust-analyzer cargo rust-apt 0.8.0 util/NumSys#Decimal# => (1000.0_f64, "TB", "GB", "MB", "KB"),
88 };
89
90 let powers = [
91 (num.powirust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]powi().(4), tera),
92 (num.powirust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]powi().(3), giga),
93 (num.powirust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]powi().(2), mega),
94 (num, kilo),
95 ];
96
97 for (divisor, unit) in powers {
98 if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().divisor {
99 return formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:.2} {unit}", val /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). divisor);
100 }
101 }
102 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{val} B")
103 }
104
105 /// Converts seconds into a human readable time string.
106 pub fn time_strrust-analyzer cargo rust-apt 0.8.0 util/time_str().(seconds: u64) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
107 if seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().24 {
108 return formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
109 "{}d {}h {}min {}s",
110 seconds /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 24,
111 (seconds /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60) %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 24,
112 (seconds /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60) %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 60,
113 seconds %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 60,
114 );
115 }
116 if seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().60 {
117 return formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
118 "{}h {}min {}s",
119 (seconds /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60 /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60) %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 24,
120 (seconds /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60) %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 60,
121 seconds %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 60,
122 );
123 }
124 if seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().60 {
125 return formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}min {}s", (seconds /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). 60) %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 60, seconds %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). 60,);
126 }
127 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{seconds}s")
128 }
129
130 /// Get an APT-styled progress bar.
131 ///
132 /// # Returns:
133 /// * [`String`] representing the progress bar.
134 ///
135 /// # Example:
136 /// ```
137 /// use rust_apt::util::get_apt_progress_string;
138 /// let progress = get_apt_progress_string(0.5, 10);
139 /// assert_eq!(progress, "[####....]");
140 /// ```
141 pub fn get_apt_progress_stringrust-analyzer cargo rust-apt 0.8.0 util/get_apt_progress_string().(percent: f32, output_width: u32) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
142 rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::get_apt_progress_stringrust-analyzer cargo rust-apt 0.8.0 util/raw/get_apt_progress_string().(percent, output_width)
143 }
144
145 /// Lock the APT lockfile.
146 /// This should be done before modifying any APT files
147 /// such as with [`crate::cache::Cache::update`]
148 /// and then [`apt_unlock`] should be called after.
149 ///
150 /// This Function Requires root
151 ///
152 /// If [`apt_lock`] is called `n` times, [`apt_unlock`] must also be called `n`
153 /// times to release all acquired locks.
154 ///
155 /// # Known Error Messages:
156 /// * `E:Could not open lock file /var/lib/dpkg/lock-frontend - open (13:
157 /// Permission denied)`
158 /// * `E:Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend),
159 /// are you root?`
160 pub fn apt_lockrust-analyzer cargo rust-apt 0.8.0 util/apt_lock().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), AptErrorsrust-analyzer cargo rust-apt 0.8.0 error/AptErrors#> {
161 configrust-analyzer cargo rust-apt 0.8.0 config/::init_config_systemrust-analyzer cargo rust-apt 0.8.0 config/init_config_system().();
162 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::apt_lockrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_lock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
163 }
164
165 /// Unlock the APT lockfile.
166 pub fn apt_unlockrust-analyzer cargo rust-apt 0.8.0 util/apt_unlock().() {
167 configrust-analyzer cargo rust-apt 0.8.0 config/::init_config_systemrust-analyzer cargo rust-apt 0.8.0 config/init_config_system().();
168 rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::apt_unlockrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_unlock().()
169 }
170
171 /// Unlock the Dpkg lockfile.
172 /// This should be done before manually running
173 /// [`crate::cache::Cache::do_install`]
174 /// and then [`apt_unlock_inner`] should be called after.
175 ///
176 /// This Function Requires root
177 pub fn apt_lock_innerrust-analyzer cargo rust-apt 0.8.0 util/apt_lock_inner().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), AptErrorsrust-analyzer cargo rust-apt 0.8.0 error/AptErrors#> {
178 configrust-analyzer cargo rust-apt 0.8.0 config/::init_config_systemrust-analyzer cargo rust-apt 0.8.0 config/init_config_system().();
179 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::apt_lock_innerrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_lock_inner().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
180 }
181
182 /// Unlock the Dpkg lockfile.
183 pub fn apt_unlock_innerrust-analyzer cargo rust-apt 0.8.0 util/apt_unlock_inner().() {
184 configrust-analyzer cargo rust-apt 0.8.0 config/::init_config_systemrust-analyzer cargo rust-apt 0.8.0 config/init_config_system().();
185 rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::apt_unlock_innerrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_unlock_inner().()
186 }
187
188 /// Checks if any locks are currently active for the lockfile. Note that this
189 /// will only return [`true`] if the current process has an active lock, while
190 /// calls to [`apt_lock`] will return an [`AptErrors`] if another process has an
191 /// active lock.
192 pub fn apt_is_lockedrust-analyzer cargo rust-apt 0.8.0 util/apt_is_locked().() -> bool {
193 configrust-analyzer cargo rust-apt 0.8.0 config/::init_config_systemrust-analyzer cargo rust-apt 0.8.0 config/init_config_system().();
194 rawrust-analyzer cargo rust-apt 0.8.0 util/raw/::apt_is_lockedrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_is_locked().()
195 }
196
197 /// Reference implementation to print broken packages just like apt does.
198 ///
199 /// ## Returns [`None`] if the package is not considered broken
200 ///
201 /// ## now:
202 /// * [true] = When checking broken packages before modifying the cache.
203 /// * [false] = When checking broken packages after modifying the cache.
204 pub fn show_broken_pkgrust-analyzer cargo rust-apt 0.8.0 util/show_broken_pkg().(cache: &Cacherust-analyzer cargo rust-apt 0.8.0 cache/Cache#, pkg: &Packagerust-analyzer cargo rust-apt 0.8.0 iterators/package/Package#, now: bool) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
205 // If the package isn't broken for the state Return None
206 if (now && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.is_now_brokenrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]is_now_broken().()) || (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().now && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pkg.is_inst_brokenrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]is_inst_broken().()) {
207 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
208 };
209
210 let mut broken_string = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
211
212 broken_string rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" {pkg} :");
213
214 // Pick the proper version based on now status.
215 // else Return with just the package name like Apt does.
216 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ver) = (match now {
217 true => pkg.installedrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]installed().(),
218 false => pkg.install_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]install_version().(),
219 }) else {
220 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()."\n";
221 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(broken_string);
222 };
223
224 let indent = pkg.namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().3;
225 let mut first = true;
226
227 // ShowBrokenDeps
228 for dep in ver.depends_maprust-analyzer cargo rust-apt 0.8.0 iterators/version/impl#[`Version<'a>`]depends_map().().valuesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]values().().flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
229 for (i, base_dep) in dep.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
230 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cache.depcacherust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]depcache().().is_important_deprust-analyzer cargo rust-apt 0.8.0 depcache/raw/impl#[PkgDepCache]is_important_dep().(base_dep) {
231 continue;
232 }
233
234 let dep_flag = if now { DepFlagsrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepFlags/::DepGNowrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepFlags/DepGNow. } else { DepFlagsrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepFlags/::DepInstallrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/DepFlags/DepInstall. };
235
236 if cache.depcacherust-analyzer cargo rust-apt 0.8.0 cache/impl#[Cache]depcache().().dep_staterust-analyzer cargo rust-apt 0.8.0 depcache/raw/impl#[PkgDepCache]dep_state().(base_dep) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().dep_flag rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().dep_flag {
237 continue;
238 }
239
240 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().first {
241 broken_string rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&" ".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(indent);
242 }
243 first = false;
244
245 // If it's the first or Dep
246 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
247 broken_string rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&" ".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(base_dep.dep_typerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]dep_type().().as_refrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[DepType][`AsRef<str>`]as_ref().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().3);
248 } else {
249 broken_string rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" {}: ", base_dep.dep_typerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]dep_type().())
250 }
251
252 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().base_dep.target_packagerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]target_package().().namerust-analyzer cargo rust-apt 0.8.0 iterators/package/raw/impl#[PkgIterator]name().();
253
254 if let (Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ver_str), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(comp)) = (base_dep.target_verrust-analyzer cargo rust-apt 0.8.0 iterators/dependency/raw/impl#[DepIterator]target_ver().(), base_dep.comp_typerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]comp_type().()) {
255 broken_string rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" ({comp} {ver_str})");
256 }
257
258 let target = base_dep.target_packagerust-analyzer cargo rust-apt 0.8.0 iterators/dependency/impl#[`BaseDep<'a>`]target_package().();
259 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().target.has_providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]has_provides().() {
260 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target_ver) = target.install_versionrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]install_version().() {
261 broken_string rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" but {target_ver} is to be installed")
262 } else if target.candidaterust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]candidate().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
263 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()." but it is not going to be installed";
264 } else if target.has_providesrust-analyzer cargo rust-apt 0.8.0 iterators/package/impl#[`Package<'a>`]has_provides().() {
265 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()." but it is a virtual package";
266 } else {
267 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()." but it is not installable";
268 }
269 }
270
271 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().dep.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
272 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()." or"
273 }
274 broken_string rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()."\n";
275 }
276 }
277 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(broken_string)
278 }
279
280 #[cxxrust-analyzer cargo cxx 1.0.199 crate/::bridgerust-analyzer cargo cxxbridge-macro 1.0.199 bridge:]
281 pub(craterust-analyzer cargo rust-apt 0.8.0 crate/) mod rawrust-analyzer cargo rust-apt 0.8.0 util/raw/ {
282 unsafe extern "C++" {
283 includerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include!!("rust-apt/apt-pkg-c/util.h");
284
285 /// Compares two package versions, `ver1` and `ver2`. The returned
286 /// integer's value is mapped to one of the following integers:
287 /// - Less than 0: `ver1` is less than `ver2`.
288 /// - Equal to 0: `ver1` is equal to `ver2`.
289 /// - Greater than 0: `ver1` is greater than `ver2`.
290 ///
291 /// Unless you have a specific need for otherwise, you should probably
292 /// use [`crate::util::cmp_versions`] instead.
293 pub fn cmp_versionsrust-analyzer cargo rust-apt 0.8.0 util/raw/cmp_versions().(ver1: &str, ver2: &str) -> i32;
294
295 /// Return an APT-styled progress bar (`[####..]`).
296 pub fn get_apt_progress_stringrust-analyzer cargo rust-apt 0.8.0 util/raw/get_apt_progress_string().(percent: f32, output_width: u32) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
297
298 /// Lock the lockfile.
299 pub fn apt_lockrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_lock().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<()>;
300
301 /// Unock the lockfile.
302 pub fn apt_unlockrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_unlock().();
303
304 /// Lock the Dpkg lockfile.
305 pub fn apt_lock_innerrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_lock_inner().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<()>;
306
307 /// Unlock the Dpkg lockfile.
308 pub fn apt_unlock_innerrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_unlock_inner().();
309
310 /// Check if the lockfile is locked.
311 pub fn apt_is_lockedrust-analyzer cargo rust-apt 0.8.0 util/raw/apt_is_locked().() -> bool;
312 }
313 }