pacsea/index/distro.rs
1//! Distro-specific helpers used across the app.
2
3/// What: Determine if a package name is Manjaro-branded
4///
5/// Input:
6/// - `name` package name
7///
8/// Output:
9/// - `true` if it starts with "manjaro-" (case-insensitive)
10///
11/// Details:
12/// - Compares a lowercased name with the "manjaro-" prefix.
13#[must_use]
14pub fn is_name_manjaro(name: &str) -> bool {
15 name.to_lowercase().starts_with("manjaro-")
16}
17
18/// What: Determine if a package or its owner indicates Manjaro
19///
20/// Input:
21/// - `name` package name; `owner` maintainer/owner string
22///
23/// Output:
24/// - `true` if name starts with "manjaro-" or owner contains "manjaro" (case-insensitive)
25///
26/// Details:
27/// - Lowercases both inputs and checks the prefix/substring rules.
28#[must_use]
29pub fn is_manjaro_name_or_owner(name: &str, owner: &str) -> bool {
30 let name_l = name.to_lowercase();
31 let owner_l = owner.to_lowercase();
32 name_l.starts_with("manjaro-") || owner_l.contains("manjaro")
33}
34
35/// What: Check if a repo name is an `EndeavourOS` repo
36///
37/// Input:
38/// - `repo` repository name
39///
40/// Output:
41/// - `true` for "eos" or "endeavouros" (case-insensitive)
42///
43/// Details:
44/// - Lowercases and matches exact names.
45#[must_use]
46pub fn is_eos_repo(repo: &str) -> bool {
47 let r = repo.to_lowercase();
48 r == "eos" || r == "endeavouros"
49}
50
51/// What: Check if a repo name belongs to `CachyOS`
52///
53/// Input:
54/// - `repo` repository name
55///
56/// Output:
57/// - `true` if it starts with "cachyos" (case-insensitive)
58///
59/// Details:
60/// - Lowercases and checks the "cachyos" prefix.
61#[must_use]
62pub fn is_cachyos_repo(repo: &str) -> bool {
63 let r = repo.to_lowercase();
64 r.starts_with("cachyos")
65}
66
67/// What: Check if a repo name belongs to Artix Linux
68///
69/// Input:
70/// - `repo` repository name
71///
72/// Output:
73/// - `true` if it matches known Artix repository names (case-insensitive)
74///
75/// Details:
76/// - Checks against the list of Artix repositories: omniverse, universe, lib32, galaxy, world, system.
77#[must_use]
78pub fn is_artix_repo(repo: &str) -> bool {
79 let r = repo.to_lowercase();
80 matches!(
81 r.as_str(),
82 "omniverse" | "universe" | "lib32" | "galaxy" | "world" | "system"
83 )
84}
85
86/// What: Check if a repo name is the Artix omniverse repository.
87#[must_use]
88pub const fn is_artix_omniverse(repo: &str) -> bool {
89 repo.eq_ignore_ascii_case("omniverse")
90}
91
92/// What: Check if a repo name is the Artix universe repository.
93#[must_use]
94pub const fn is_artix_universe(repo: &str) -> bool {
95 repo.eq_ignore_ascii_case("universe")
96}
97
98/// What: Check if a repo name is the Artix lib32 repository.
99#[must_use]
100pub const fn is_artix_lib32(repo: &str) -> bool {
101 repo.eq_ignore_ascii_case("lib32")
102}
103
104/// What: Check if a repo name is the Artix galaxy repository.
105#[must_use]
106pub const fn is_artix_galaxy(repo: &str) -> bool {
107 repo.eq_ignore_ascii_case("galaxy")
108}
109
110/// What: Check if a repo name is the Artix world repository.
111#[must_use]
112pub const fn is_artix_world(repo: &str) -> bool {
113 repo.eq_ignore_ascii_case("world")
114}
115
116/// What: Check if a repo name is the Artix system repository.
117#[must_use]
118pub const fn is_artix_system(repo: &str) -> bool {
119 repo.eq_ignore_ascii_case("system")
120}
121
122#[cfg(not(target_os = "windows"))]
123/// What: Known `EndeavourOS` repo names usable with pacman -Sl
124///
125/// Output:
126/// - Static slice of repo names
127///
128/// Details:
129/// - Returns `["eos", "endeavouros"]`.
130pub const fn eos_repo_names() -> &'static [&'static str] {
131 &["endeavouros"]
132}
133
134#[cfg(not(target_os = "windows"))]
135/// What: Known `CachyOS` repo names usable with pacman -Sl
136///
137/// Output:
138/// - Static slice of repo names
139///
140/// Details:
141/// - Includes multiple generation-specific names (v3/v4) for compatibility.
142pub const fn cachyos_repo_names() -> &'static [&'static str] {
143 &[
144 "cachyos",
145 "cachyos-core",
146 "cachyos-extra",
147 "cachyos-v3",
148 "cachyos-core-v3",
149 "cachyos-extra-v3",
150 "cachyos-v4",
151 "cachyos-core-v4",
152 "cachyos-extra-v4",
153 ]
154}
155
156#[cfg(not(target_os = "windows"))]
157/// What: Known Artix Linux repo names usable with pacman -Sl
158///
159/// Output:
160/// - Static slice of repo names
161///
162/// Details:
163/// - Returns the standard Artix repositories: omniverse, universe, lib32, galaxy, world, system.
164pub const fn artix_repo_names() -> &'static [&'static str] {
165 &[
166 "omniverse",
167 "universe",
168 "lib32",
169 "galaxy",
170 "world",
171 "system",
172 ]
173}
174
175/// What: Heuristic to treat a name as EndeavourOS-branded
176///
177/// Input:
178/// - `name` package name
179///
180/// Output:
181/// - `true` if it contains "eos-" (case-insensitive)
182///
183/// Details:
184/// - Used when reconstructing installed-only items not present in the official index.
185#[must_use]
186pub fn is_eos_name(name: &str) -> bool {
187 name.to_lowercase().contains("eos-")
188}
189
190#[cfg(test)]
191mod tests {
192 #[test]
193 /// What: Validate Manjaro-specific name detection.
194 ///
195 /// Inputs:
196 /// - Sample strings covering positive and negative cases.
197 ///
198 /// Output:
199 /// - Assertions confirming only Manjaro-branded names return true.
200 ///
201 /// Details:
202 /// - Exercises case-insensitive prefix handling.
203 fn manjaro_name_detection() {
204 assert!(super::is_name_manjaro("manjaro-alsa"));
205 assert!(super::is_name_manjaro("Manjaro-foo"));
206 assert!(!super::is_name_manjaro("alsa"));
207 }
208
209 #[test]
210 /// What: Ensure Manjaro identification works on name or owner fields.
211 ///
212 /// Inputs:
213 /// - Pairs of (name, owner) covering positive and negative scenarios.
214 ///
215 /// Output:
216 /// - Assertions verifying either field triggers detection.
217 ///
218 /// Details:
219 /// - Confirms substring search on owner and prefix match on name.
220 fn manjaro_name_or_owner_detection() {
221 assert!(super::is_manjaro_name_or_owner("manjaro-alsa", ""));
222 assert!(super::is_manjaro_name_or_owner("alsa", "Manjaro Team"));
223 assert!(!super::is_manjaro_name_or_owner("alsa", "Arch Linux"));
224 }
225
226 #[test]
227 /// What: Confirm repo heuristics for `EOS` and `CachyOS`.
228 ///
229 /// Inputs:
230 /// - Various repo strings spanning expected matches and misses.
231 ///
232 /// Output:
233 /// - Assertions that only target repos return true.
234 ///
235 /// Details:
236 /// - Checks both equality and prefix-based rules.
237 fn eos_and_cachyos_repo_rules() {
238 assert!(super::is_eos_repo("eos"));
239 assert!(super::is_eos_repo("EndeavourOS"));
240 assert!(!super::is_eos_repo("core"));
241
242 assert!(super::is_cachyos_repo("cachyos-core"));
243 assert!(super::is_cachyos_repo("CachyOS-extra"));
244 assert!(!super::is_cachyos_repo("extra"));
245 }
246
247 #[test]
248 /// What: Verify EOS-branded name heuristic.
249 ///
250 /// Inputs:
251 /// - Strings with and without the "eos-" fragment.
252 ///
253 /// Output:
254 /// - Assertions matching expected boolean results.
255 ///
256 /// Details:
257 /// - Demonstrates case-insensitive substring detection.
258 fn eos_name_rule() {
259 assert!(super::is_eos_name("eos-hello"));
260 assert!(super::is_eos_name("my-eos-helper"));
261 assert!(!super::is_eos_name("hello"));
262 }
263
264 #[test]
265 /// What: Confirm repo heuristics for Artix Linux.
266 ///
267 /// Inputs:
268 /// - Various repo strings spanning expected matches and misses.
269 ///
270 /// Output:
271 /// - Assertions that only Artix repos return true.
272 ///
273 /// Details:
274 /// - Checks case-insensitive matching for all Artix repository names.
275 fn artix_repo_rules() {
276 assert!(super::is_artix_repo("omniverse"));
277 assert!(super::is_artix_repo("Omniverse"));
278 assert!(super::is_artix_repo("universe"));
279 assert!(super::is_artix_repo("lib32"));
280 assert!(super::is_artix_repo("galaxy"));
281 assert!(super::is_artix_repo("world"));
282 assert!(super::is_artix_repo("system"));
283 assert!(!super::is_artix_repo("core"));
284 assert!(!super::is_artix_repo("extra"));
285 assert!(!super::is_artix_repo("cachyos"));
286 }
287}