1pub mod fetch;
6pub mod index;
7pub mod layout;
8pub mod lock;
9pub mod provenance;
10pub mod reference;
11pub mod referrer;
12pub mod store;
13
14use std::path::PathBuf;
15
16pub use fetch::{UpdateOutcome, ensure, install_local, pull, store_referrer, update};
17pub use provenance::{Provenance, ProvenanceError, Source};
18pub use reference::{ParseRefError, Ref};
19pub use referrer::{ReferrerInfo, referrer_kind};
20pub use store::{Store, StoreError, Stored};
21
22#[derive(Debug, thiserror::Error)]
24pub enum LocationError {
25 #[error("cannot determine a local data directory for the component store")]
26 NoDataDir,
27}
28
29pub fn store_dir() -> Result<PathBuf, LocationError> {
37 if let Some(dir) = std::env::var_os("ACT_STORE_DIR") {
38 return Ok(PathBuf::from(dir));
39 }
40 let base = dirs::data_local_dir().ok_or(LocationError::NoDataDir)?;
41 Ok(base.join("act").join("store"))
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn env_override_wins() {
50 let prev = std::env::var_os("ACT_STORE_DIR");
51 unsafe { std::env::set_var("ACT_STORE_DIR", "/tmp/act-store-test-xyz") };
52 assert_eq!(
53 store_dir().unwrap(),
54 std::path::PathBuf::from("/tmp/act-store-test-xyz")
55 );
56 match prev {
57 Some(v) => unsafe { std::env::set_var("ACT_STORE_DIR", v) },
58 None => unsafe { std::env::remove_var("ACT_STORE_DIR") },
59 }
60 }
61}