Skip to main content

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: Check if a repo name belongs to `BlackArch`
176///
177/// Input:
178/// - `repo` repository name
179///
180/// Output:
181/// - `true` if it matches "blackarch" (case-insensitive)
182///
183/// Details:
184/// - Lowercases and checks exact equality.
185#[must_use]
186pub const fn is_blackarch_repo(repo: &str) -> bool {
187    repo.eq_ignore_ascii_case("blackarch")
188}
189
190#[cfg(not(target_os = "windows"))]
191/// What: Known `BlackArch` repo names usable with pacman -Sl
192///
193/// Output:
194/// - Static slice of repo names
195///
196/// Details:
197/// - Returns `["blackarch"]`.
198pub const fn blackarch_repo_names() -> &'static [&'static str] {
199    &["blackarch"]
200}
201
202/// What: Heuristic to treat a name as EndeavourOS-branded
203///
204/// Input:
205/// - `name` package name
206///
207/// Output:
208/// - `true` if it contains "eos-" (case-insensitive)
209///
210/// Details:
211/// - Used when reconstructing installed-only items not present in the official index.
212#[must_use]
213pub fn is_eos_name(name: &str) -> bool {
214    name.to_lowercase().contains("eos-")
215}
216
217#[cfg(test)]
218mod tests {
219    #[test]
220    /// What: Validate Manjaro-specific name detection.
221    ///
222    /// Inputs:
223    /// - Sample strings covering positive and negative cases.
224    ///
225    /// Output:
226    /// - Assertions confirming only Manjaro-branded names return true.
227    ///
228    /// Details:
229    /// - Exercises case-insensitive prefix handling.
230    fn manjaro_name_detection() {
231        assert!(super::is_name_manjaro("manjaro-alsa"));
232        assert!(super::is_name_manjaro("Manjaro-foo"));
233        assert!(!super::is_name_manjaro("alsa"));
234    }
235
236    #[test]
237    /// What: Ensure Manjaro identification works on name or owner fields.
238    ///
239    /// Inputs:
240    /// - Pairs of (name, owner) covering positive and negative scenarios.
241    ///
242    /// Output:
243    /// - Assertions verifying either field triggers detection.
244    ///
245    /// Details:
246    /// - Confirms substring search on owner and prefix match on name.
247    fn manjaro_name_or_owner_detection() {
248        assert!(super::is_manjaro_name_or_owner("manjaro-alsa", ""));
249        assert!(super::is_manjaro_name_or_owner("alsa", "Manjaro Team"));
250        assert!(!super::is_manjaro_name_or_owner("alsa", "Arch Linux"));
251    }
252
253    #[test]
254    /// What: Confirm repo heuristics for `EOS` and `CachyOS`.
255    ///
256    /// Inputs:
257    /// - Various repo strings spanning expected matches and misses.
258    ///
259    /// Output:
260    /// - Assertions that only target repos return true.
261    ///
262    /// Details:
263    /// - Checks both equality and prefix-based rules.
264    fn eos_and_cachyos_repo_rules() {
265        assert!(super::is_eos_repo("eos"));
266        assert!(super::is_eos_repo("EndeavourOS"));
267        assert!(!super::is_eos_repo("core"));
268
269        assert!(super::is_cachyos_repo("cachyos-core"));
270        assert!(super::is_cachyos_repo("CachyOS-extra"));
271        assert!(!super::is_cachyos_repo("extra"));
272    }
273
274    #[test]
275    /// What: Verify EOS-branded name heuristic.
276    ///
277    /// Inputs:
278    /// - Strings with and without the "eos-" fragment.
279    ///
280    /// Output:
281    /// - Assertions matching expected boolean results.
282    ///
283    /// Details:
284    /// - Demonstrates case-insensitive substring detection.
285    fn eos_name_rule() {
286        assert!(super::is_eos_name("eos-hello"));
287        assert!(super::is_eos_name("my-eos-helper"));
288        assert!(!super::is_eos_name("hello"));
289    }
290
291    #[test]
292    /// What: Confirm repo heuristics for `BlackArch`.
293    ///
294    /// Inputs:
295    /// - Various repo strings spanning expected matches and misses.
296    ///
297    /// Output:
298    /// - Assertions that only `BlackArch` repo returns true.
299    ///
300    /// Details:
301    /// - Checks case-insensitive exact matching.
302    fn blackarch_repo_rules() {
303        assert!(super::is_blackarch_repo("blackarch"));
304        assert!(super::is_blackarch_repo("BlackArch"));
305        assert!(super::is_blackarch_repo("BLACKARCH"));
306        assert!(!super::is_blackarch_repo("blackarch-extra"));
307        assert!(!super::is_blackarch_repo("core"));
308        assert!(!super::is_blackarch_repo("cachyos"));
309        assert!(!super::is_blackarch_repo("eos"));
310    }
311
312    #[test]
313    /// What: Confirm repo heuristics for Artix Linux.
314    ///
315    /// Inputs:
316    /// - Various repo strings spanning expected matches and misses.
317    ///
318    /// Output:
319    /// - Assertions that only Artix repos return true.
320    ///
321    /// Details:
322    /// - Checks case-insensitive matching for all Artix repository names.
323    fn artix_repo_rules() {
324        assert!(super::is_artix_repo("omniverse"));
325        assert!(super::is_artix_repo("Omniverse"));
326        assert!(super::is_artix_repo("universe"));
327        assert!(super::is_artix_repo("lib32"));
328        assert!(super::is_artix_repo("galaxy"));
329        assert!(super::is_artix_repo("world"));
330        assert!(super::is_artix_repo("system"));
331        assert!(!super::is_artix_repo("core"));
332        assert!(!super::is_artix_repo("extra"));
333        assert!(!super::is_artix_repo("cachyos"));
334    }
335}