1use std::path::PathBuf;
2use std::sync::{OnceLock, RwLock};
3
4fn pkg_dirs_store() -> &'static RwLock<Vec<PathBuf>> {
5 static PKG_DIRS: OnceLock<RwLock<Vec<PathBuf>>> = OnceLock::new();
6 PKG_DIRS.get_or_init(|| RwLock::new(Vec::new()))
7}
8
9pub fn set_pkg_dirs(dirs: Vec<PathBuf>) {
11 if let Ok(mut guard) = pkg_dirs_store().write() {
12 *guard = dirs;
13 }
14}
15
16pub fn get_pkg_dirs() -> Vec<PathBuf> {
18 pkg_dirs_store()
19 .read()
20 .map(|dirs| dirs.clone())
21 .unwrap_or_default()
22}
23
24pub fn find_in_pkg_dirs(filename: &str) -> Option<PathBuf> {
27 for dir in get_pkg_dirs() {
28 let path = dir.join(filename);
29 if path.exists() && path.is_file() {
30 return Some(path);
31 }
32 }
33 None
34}