vivacity_core/
platform.rs1use std::path::PathBuf;
9
10#[derive(Debug, PartialEq, Eq)]
11pub struct PlatformFailure {
12 pub requirement: String,
14 pub constraint: String,
15 pub required_by: Option<String>,
17 pub reason: FailureReason,
18}
19
20#[derive(Debug, PartialEq, Eq)]
21pub enum FailureReason {
22 Missing,
23 Mismatch { installed: String },
24 Unsupported,
25}
26
27pub fn parallel_io() -> bool {
33 match std::env::var("VIVACITY_PARALLEL_IO") {
34 Ok(v) => v != "0" && !v.is_empty(),
35 Err(_) => cfg!(target_os = "linux"),
36 }
37}
38
39pub fn cache_dir() -> PathBuf {
40 if let Ok(d) = std::env::var("VIVACITY_CACHE_DIR") {
41 return PathBuf::from(d);
42 }
43 #[cfg(windows)]
44 {
45 if let Ok(l) = std::env::var("LOCALAPPDATA") {
46 if !l.is_empty() {
47 return PathBuf::from(l).join("vivacity");
48 }
49 }
50 }
51 if let Ok(xdg) = std::env::var("XDG_CACHE_HOME") {
52 return PathBuf::from(xdg).join("vivacity");
53 }
54 let home = std::env::var("HOME")
55 .or_else(|_| std::env::var("USERPROFILE"))
56 .unwrap_or_else(|_| ".".to_owned());
57 if cfg!(target_os = "macos") {
58 PathBuf::from(home).join("Library/Caches/vivacity")
59 } else {
60 PathBuf::from(home).join(".cache/vivacity")
61 }
62}
63
64pub fn is_ignored(requirement: &str, ignored: &[String]) -> bool {
66 ignored.iter().any(|pat| {
67 let pat = pat.strip_suffix('+').unwrap_or(pat);
68 pat == "*"
69 || pat == requirement
70 || pat
71 .strip_suffix('*')
72 .is_some_and(|prefix| requirement.starts_with(prefix))
73 })
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn ignore_patterns() {
82 let pats = |v: &[&str]| v.iter().map(|s| (*s).to_owned()).collect::<Vec<_>>();
83 assert!(is_ignored("php", &pats(&["*"])));
84 assert!(is_ignored("ext-gd", &pats(&["ext-*"])));
85 assert!(!is_ignored("php", &pats(&["ext-*"])));
86 assert!(is_ignored("ext-gd", &pats(&["ext-gd+"])));
87 assert!(!is_ignored("ext-intl", &pats(&["ext-gd"])));
88 }
89}