Skip to main content

act_store/
lib.rs

1//! Local OCI-layout component store shared by act-cli and act-toolserver.
2//!
3//! See `docs/specs/2026-05-26-shared-component-store-design.md`.
4
5pub 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/// Error type for store-location resolution.
23#[derive(Debug, thiserror::Error)]
24pub enum LocationError {
25    #[error("cannot determine a local data directory for the component store")]
26    NoDataDir,
27}
28
29/// Resolve the shared store directory.
30///
31/// Priority: `ACT_STORE_DIR` env var, else the platform machine-local data
32/// dir under `act/store`:
33/// - Linux:   `$XDG_DATA_HOME/act/store` (`~/.local/share/act/store`)
34/// - macOS:   `~/Library/Application Support/act/store`
35/// - Windows: `%LOCALAPPDATA%\act\store`
36pub 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}