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